#include "octave.h" const Plot& operator<<(std::ostream& out, const Plot& plot) { out << "x = [ "; for(const auto& [x,y] : plot.data) { out << x << " "; } out << "]\n"; out << "y = [ "; for(const auto& [x,y] : plot.data) { out << y << " "; } out << "]\n"; out << "scatter(x, y)\n"; return plot; } const std::string& Plot::getTitle() const { return title; } void Plot::add(const std::pair& point) { data.push_back(point); } void Plot::add(double y) { //if(y < 1000.0) { add({x, y}); } } void Plot::setX(double x) { this->x = x; } Octave::Octave(const std::string& file) : out(file + ".m") , file(file) { } Octave::~Octave() { if(!out.good()) { return; } out << "fig = figure()\n"; out << "hold on;\n"; for(const auto& plot : plots) { out << plot; } out << "legend ({"; for(const auto& plot : plots) { out << "'" << plot.getTitle() << "' " ; } out << "}, 'location', 'east');\n"; out << "xlabel ('" << x_axis << "');\n"; out << "ylabel ('" << y_axis << "');\n"; // out << "set(gca, 'yscale', 'log')\n"; out << "set(gcf, 'PaperPosition', [0 0 5 5])\n"; out << "set(gcf, 'PaperSize', [5 5])\n"; out << "print(fig, '" << file << ".pdf');\n"; } Plot& Octave::add(const std::string& title) { plots.push_back(title); return plots.back(); } void Octave::setAxis(const std::string& x_axis, const std::string& y_axis) { this->x_axis = x_axis; this->y_axis = y_axis; }