Description

Class for lotting data with GNUplot.

This is a basic utility class, it just saves a temporary gpl file on disk and then calls the GNUplot utility from the system shell, so it does not require to link GNUplot libraries. If the GNUplot is not installed, simply nothing happens. NOTE: the GNUplot should be installed in your platform. Supported from release 4.6. NOTE: the GNUplot executable must be available in your PATH, i.e. if you type 'gnuplot' in the cmd window, it should be executed. If this does not happens, add the directory with the GNUplot binary to your PATH. In Linux platforms this should be already ok by default. NOTE: if no plot is displayed, open a cmd shell, type "gnuplot __tmp_gnuplot.gpl -persist" and see which error is displayed.

#include <ChGnuPlot.h>

Public Member Functions

 ChGnuPlot (const char *mgpl_filename="__tmp_gnuplot.gpl")
 
void SetPersist (bool mpersist)
 If false, the GNUplot will close soon after the plot. More...
 
void SetCommand (const char *command)
 This is the main feature. More...
 
ChGnuPlotoperator<< (const char *command)
 This is equivalent to SetCommand().
 
void Plot (const char *datfile, int colX, int colY, const char *title, const char *customsettings=" with lines ")
 Shortcut to easy 2D plot of x,y data from a .dat external file.
 
void Plot (ChVectorDynamic<> &mx, ChVectorDynamic<> &my, const char *title, const char *customsettings=" with lines ")
 Shortcut to easy 2D plot of x,y data from two column vectors.
 
void Plot (ChMatrixConstRef mdata, int colX, int colY, const char *title, const char *customsettings=" with lines ")
 Shortcut to easy 2D plot of x,y data from two columns of a matrix.
 
void Plot (ChFunction_Recorder &mrecorder, const char *title, const char *customsettings=" with lines ")
 Shortcut to easy 2D plot of x,y data from a ChFunction_recorder.
 
void Plot (ChFunction_Oscilloscope &mrecorder, const char *title, const char *customsettings=" with lines ")
 Shortcut to easy 2D plot of x,y data from a ChFunction_recorder.
 
void Plot (ChFunction &mfunct, double xmin, double xmax, double dx, const char *title, const char *customsettings=" with lines ")
 Shortcut to easy 2D plot of x,y data from a generic ChFunction Note, if the ChFunction is of type ChFunction_Oscilloscope or ChFunction_Recorder, there are specific Plot() functions that can leverage their point-like nature in a better way.
 
void Replot ()
 Replot last plots (since the last time you used Output...() functions, if any).
 
void SetRangeX (double mmin, double mmax, bool automin=false, bool automax=false)
 Shortcut to add the command that set the X range.
 
void SetRangeY (double mmin, double mmax, bool automin=false, bool automax=false)
 Shortcut to add the command that set the Y range.
 
void SetRangeZ (double mmin, double mmax, bool automin=false, bool automax=false)
 Shortcut to add the command that set the Z range.
 
void SetTitle (const char *mlabel)
 Shortcut to add title.
 
void SetLabelX (const char *mlabel)
 Shortcut to add a label on axis.
 
void SetLabelY (const char *mlabel)
 Shortcut to add a label on axis.
 
void SetLabelZ (const char *mlabel)
 Shortcut to add a label on axis.
 
void SetGrid (bool dashed=true, double linewidth=1.0, ChColor mcolor=ChColor(0, 0, 0))
 Shortcut to add the command that turns on the grid.
 
void OutputWindow (int windownum=0)
 Set plot in a window. More...
 
void OutputPNG (const char *filename, int sizex=400, int sizey=300)
 Save plot in a png file. More...
 
void OutputEPS (const char *filename, double inchsizex=4, double inchsizey=3, bool color=true)
 Save plot in a eps file. More...
 
void OutputCustomTerminal (const char *filename, const char *terminalsetting)
 Save plot in a custom terminal. More...
 

Protected Member Functions

void FlushPlots (std::string &mscript)
 
void ExecuteGnuplot (std::string &mscript)
 
std::string d_to_str (double num)
 
std::string i_to_str (int num)
 
std::string col_to_hex (ChColor mcolor)
 

Protected Attributes

std::string gpl_filename
 
std::string commandfile
 
std::vector< ChGnuPlotDataplot > plots
 
bool persist
 

Member Function Documentation

◆ OutputCustomTerminal()

void chrono::postprocess::ChGnuPlot::OutputCustomTerminal ( const char *  filename,
const char *  terminalsetting 
)
inline

Save plot in a custom terminal.

For instance try terminalsetting ="set terminal svg size 350,262 fname 'Verdana' fsize 10" Call this before Plot() statements. Otherwise call Replot() just after.

◆ OutputEPS()

void chrono::postprocess::ChGnuPlot::OutputEPS ( const char *  filename,
double  inchsizex = 4,
double  inchsizey = 3,
bool  color = true 
)
inline

Save plot in a eps file.

Call this before Plot() statements. Otherwise call Replot() just after.

◆ OutputPNG()

void chrono::postprocess::ChGnuPlot::OutputPNG ( const char *  filename,
int  sizex = 400,
int  sizey = 300 
)
inline

Save plot in a png file.

Call this before Plot() statements. Otherwise call Replot() just after.

◆ OutputWindow()

void chrono::postprocess::ChGnuPlot::OutputWindow ( int  windownum = 0)
inline

Set plot in a window.

For multiple windows, call this with increasing windownum, interleaving with Plot() statements etc. Call this before Plot() statements. Otherwise call Replot() just after.

◆ SetCommand()

void chrono::postprocess::ChGnuPlot::SetCommand ( const char *  command)
inline

This is the main feature.

Use this function to add commands in the gnuplot script. It can be whatever gnuplot statement. Basically you would just need calls to SetCommand() followed by an Output() at the end, however to make things easier, there are some shortcut functions such as SetRangeX() ,SetGrid(), Plot etc. that populate the command file for you. It will be automatically null-terminated, so you may call it multiple times, each per line.

◆ SetPersist()

void chrono::postprocess::ChGnuPlot::SetPersist ( bool  mpersist)
inline

If false, the GNUplot will close soon after the plot.

For plotting in windows , it is better to leave it as true by default, but for plotting eps or png maybe you want it to close automatically.


The documentation for this class was generated from the following file:
  • /builds/uwsbel/chrono/src/chrono_postprocess/ChGnuPlot.h