4#include "../matrix_utils.h"
5#include "../numerics/utils.h"
28 case LINE:
return "lines ls 1";
29 case DOTS:
return "points ls 2";
31 default:
return "none";
145 void xAxis(
const std::string& name) {
155 void yAxis(
const std::string& name) {
185 const std::string& name,
187 const char* character =
nullptr) {
201 const std::string& name,
202 DataTypes dataTypeName = DataTypes::NONE,
203 const char* pointChar =
nullptr,
204 int dimensions = 2) {
205 if(dimensions <= 3) {
232 for(
size_t i = 0; i < mat.
columns(); i += dimensions) {
234 for(
size_t j = 0; j < mat.
rows(); ++j) {
235 for(
int k = 0; k < dimensions; ++k) { fprintf(
storageFile,
"%g ", mat(j, i + k)); }
243 newName =
new char[name.size() + 1];
244 std::copy(name.begin(), name.end(), newName);
245 newName[name.size()] =
'\0';
265 FILE* gnuplot = popen(
"gnuplot --persist",
"w");
268 if(i == 0) { fprintf(gnuplot,
"%s",
plotType); }
271 if(index.stop != -1) {
272 fprintf(gnuplot,
" index %d:%d with ", index.start, index.stop);
274 fprintf(gnuplot,
" index %d with ", index.start);
279 fprintf(gnuplot, i == (
numElements - 1) ?
"\n" :
",");
281 fprintf(gnuplot,
"\n");
296 double startX =
min(x);
298 double endX =
max(x);
329 char titleExtension[105];
336 fprintf(gnuplot,
"'\n");
338 fprintf(gnuplot,
"set style line 1 lt 2 lc rgb \"red\" lw 3;\nset style line 1 lt 2 lc rgb \"orange\" lw 3;\n");
341 if(
attributes.
is3D) { fprintf(gnuplot,
"set hidden3d\nset dgrid3d 30,30 qnorm 1\n"); }
378 explicit FunctionPlot(std::function<
double(
const double&)> fun,
const char* name =
"")
389 void AddData(
const double& start,
const double& end,
const double& stepSize,
const char* name) {
390 int size = (int)((end - start) / stepSize) + 2;
419 FILE* gnuplot = popen(
"gnuplot --persist",
"w");
424 fprintf(gnuplot,
"\n");
461 FILE* gnuplot = popen(
"gnuplot --persist",
"w");
464 fprintf(gnuplot,
"plot '%s' matrix with image",
dataFileName);
466 fprintf(gnuplot,
"\n");
const char * GetPlotDataTypeName(DataTypes type)
Definition: Plot.h:26
DataTypes
Definition: Plot.h:12
@ DOTS
Creates dot data.
Definition: Plot.h:16
@ LINE
Creates line data.
Definition: Plot.h:14
@ NONE
Unknown data type.
Definition: Plot.h:18
std::function< double(const double &)> Function
Function to evaluate and display.
Definition: Plot.h:370
void AddData(const double &start, const double &end, const double &stepSize, const char *name)
Definition: Plot.h:389
FunctionPlot(std::function< double(const double &)> fun, const char *name="")
Definition: Plot.h:378
Definition: Operator.h:118
void operator()(const char *colorPalette="magma.pal")
Definition: Plot.h:460
void AddData(const Matrix< double > &mat, const std::string &name)
Definition: Plot.h:451
ImagePlot(const char *name)
Definition: Plot.h:441
size_t rows() const
Definition: Matrix.h:193
size_t columns() const
Definition: Matrix.h:198
Matrix GetSlice(size_t rowStart) const
Definition: Matrix.h:609
void assertSize(const Matrix< T > &other) const
Definition: Matrix.h:334
Matrix< T > Apply(const std::function< T(T)> &fun) const
Definition: Matrix.h:375
int numElements
number elements within the plot
Definition: Plot.h:317
void AddData(const Matrix< double > &x, const Matrix< double > &y, const std::string &name, DataTypes dataType=DataTypes::NONE, const char *character=nullptr)
Definition: Plot.h:182
void yAxis(const std::string &name)
Definition: Plot.h:155
void AddData(const Matrix< double > &mat, const std::string &name, DataTypes dataTypeName=DataTypes::NONE, const char *pointChar=nullptr, int dimensions=2)
Definition: Plot.h:199
void lineWidth(const int &size)
Definition: Plot.h:171
void xAxis(const std::string &name)
Definition: Plot.h:145
const char * plotType
representation of plot type
Definition: Plot.h:311
FILE * storageFile
data storage file
Definition: Plot.h:313
const char * plotTypeName
representation of plot type
Definition: Plot.h:309
PlotBoundary bX
y-axis boundaries for the resulting plot
Definition: Plot.h:321
void writeAttributes(FILE *gnuplot) const
Definition: Plot.h:327
PlotBoundary bY
x-axis boundaries for the resulting plot
Definition: Plot.h:319
void pointSize(const int &size)
Definition: Plot.h:165
void clear_file()
Definition: Plot.h:124
PlotBoundary getBoundaries(const Matrix< double > &x) const
Definition: Plot.h:291
const char * dataFileName
data storage file name
Definition: Plot.h:307
Plot(const std::string &title="")
Definition: Plot.h:111
PlotAttributes attributes
attributes for plot
Definition: Plot.h:315
virtual void operator()() const
Definition: Plot.h:264
void title(const std::string &title)
Definition: Plot.h:135
ScatterPlot(const char *name="")
Definition: Plot.h:356
SurfacePlot(const std::string &title="")
Definition: Plot.h:407
void operator()() const override
Definition: Plot.h:418
Matrix< T > HorizontalConcat(const Matrix< T > &lhs, const Matrix< T > &rhs)
Definition: matrix_utils.h:81
T min(const Matrix< T > &mat)
Definition: matrix_utils.h:324
T max(const Matrix< T > &mat)
Definition: matrix_utils.h:292
Matrix< double > linspace(double start, double end, unsigned long num_elements)
std::vector< const char * > plotTypes
vector representing data series types
Definition: Plot.h:82
char * yAxis
y-axis label
Definition: Plot.h:64
bool is3D
signalizes 3D plot
Definition: Plot.h:70
bool is2D
signalizes 2D plot
Definition: Plot.h:72
char * xAxis
x-axis label
Definition: Plot.h:62
int pointStrength
point strength
Definition: Plot.h:66
const char * colorPalette
color used to plot elements
Definition: Plot.h:78
int lineStrength
line strength
Definition: Plot.h:68
std::vector< PlotIndex > plotIndices
vector containing dataset indices in the storage file
Definition: Plot.h:86
unsigned int isStatPlot
identifier for statistical plots for value comparison
Definition: Plot.h:74
const char * color
color used to plot elements
Definition: Plot.h:76
std::vector< const char * > characters
vector representing characters to use to display points per data series
Definition: Plot.h:84
std::vector< const char * > plotNames
vector representing data series
Definition: Plot.h:80
char * title
title label
Definition: Plot.h:60
double min
min boundary value
Definition: Plot.h:40
double max
max boundary value
Definition: Plot.h:42
int stop
end index
Definition: Plot.h:52
int start
start index
Definition: Plot.h:50