mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
mx::math::gnuPlot Class Reference

An interactive c++ interface to gnuplot.

Spawns a gnuplot sesssion and communicates with it.

Todo:
Use mxError for error reporting.

An example of using gnuPlot to plot data from a file:

gnuPlot gp; //This automatically connects, and is now ready to plot.
gp.plot("my_data_file.dat", "u 1:2 w l"); //Plots the data in the file

Arrays can be plotted directly:

std::vector<float> x;
std::vector<double> y;
//...code to populate x and y
gp.plot(x, y); //Plots y vs x.

Note that the vector data types are different – this is handled automatically.

To get a response from the gnuplot session:

std::cout << gp.getResponse("show terminal") << "\n"; //Sends the command to gnuplot, gets the response.

Error checking and reporting is not straightforward since gnuplot does not return a result if there is no error. If there is an error, it can take several hundred milliseconds for a response to be available. So for a typical plot command, say, one does not want to try to read the stderr ouput just in case as this will just time out with a delay.

For cases where a response is expected, the following example shows how to check for errors.

errno = 0;
std::string response = gp.getResponse("show terminal"); //Waits up to 0.5 seconds, or a user specified timeout.
if(response == "") //This indicates some error occurred, or a timeout.
{
if(gp.gpError())
{
std::cerr << "gnuplot returned error:\n" << gp.gpErrorMsg() << "\n";
}
else if(errno)
{
perror("error getting response: ");
}
else
{
std::cerr << "timed out\n";
}
}
else
{
std::cout << response << "\n";
}

Definition at line 192 of file gnuPlot.hpp.

#include <math/plot/gnuPlot.hpp>

Public Member Functions

int connect ()
 Connect to gnuplot. More...
 
bool gpError ()
 Return the value of the gpError flag. More...
 
std::string gpErrorMsg ()
 Return the gnuplot error message. More...
 
int command (const std::string &com, bool flush=true)
 Send a command to gnuplot. More...
 
int checkResponse (std::string &response, double timeout=0)
 Check for a response from gnuplot. More...
 
std::string getResponse (const std::string &com, double timeout=0.5)
 Get a response from gnuplot for a given command. More...
 
int replot ()
 Issue the replot command. More...
 
int xrange (double x0, double x1)
 Set the x-axis range. More...
 
int xrange ()
 Unset the x-axis range. More...
 
int yrange (double y0, double y1)
 Set the y-axis range. More...
 
int yrange ()
 Unset the y-axis range. More...
 
int logy ()
 Set the y axis to log scale. More...
 
int logx ()
 Set the x axis to log scale. More...
 
int logxy ()
 Set the x and y axes to log scale. More...
 
int ulogy ()
 Unset the y axis from log scale. More...
 
int ulogx ()
 Unset the x axis from log scale. More...
 
int ulogxy ()
 Unset the x and y axes from log scale. More...
 
int plot (const std::string &fname, const std::string &modifiers, const std::string &title, const std::string &name)
 Plot from a file specifying all curve components. More...
 
int plot (const std::string &fname, const std::string &modifiers, const std::string &name)
 Plot from a file without specifying the title. More...
 
int plot (const std::string &fname, const std::string &name)
 Plot from a file without modifiers. More...
 
int plot (const std::string &fname)
 Plot from a file without specifying the name or any modifiers. More...
 
template<typename dataT >
int plot (const dataT *y, size_t N, const std::string &modifiers, const std::string &title, const std::string &name)
 Plot data from an array. More...
 
template<typename dataT >
int plot (const dataT *y, size_t N, const std::string &modifiers, const std::string &name)
 Plot data from an array. More...
 
template<typename dataT >
int plot (const dataT *y, size_t N, const std::string &name)
 Plot data from an array. More...
 
template<typename dataT >
int plot (const dataT *y, size_t N)
 Plot data from an array. More...
 
template<typename dataT >
int plot (const std::vector< dataT > &y, const std::string &modifiers, const std::string &title, const std::string &name)
 Plot data from a vector. More...
 
template<typename dataT >
int plot (const std::vector< dataT > &y, const std::string &modifiers, const std::string &name)
 Plot data from a vector. More...
 
template<typename dataT >
int plot (const std::vector< dataT > &y, const std::string &name)
 Plot data from a vector. More...
 
template<typename dataT >
int plot (const std::vector< dataT > &y)
 Plot data from a vector. More...
 
template<typename dataTx , typename dataTy >
int plot (const dataTx *x, const dataTy *y, size_t N, const std::string &modifiers, const std::string &title, const std::string &name)
 Plot y vs. x data from arrays. More...
 
template<typename dataTx , typename dataTy >
int plot (const dataTx *x, const dataTy *y, size_t N, const std::string &modifiers, const std::string &name)
 Plot y vs. x data from arrays. More...
 
template<typename dataTx , typename dataTy >
int plot (const dataTx *x, const dataTy *y, size_t N, const std::string &name)
 Plot y vs. x data from arrays. More...
 
template<typename dataTx , typename dataTy >
int plot (const dataTx *x, const dataTy *y, size_t N)
 Plot y vs. x data from arrays. More...
 
template<typename dataTx , typename dataTy >
int plot (const std::vector< dataTx > &x, const std::vector< dataTy > &y, const std::string &modifiers, const std::string &title, const std::string &name)
 Plot y vs. x data from vectors. More...
 
template<typename dataTx , typename dataTy >
int plot (const std::vector< dataTx > &x, const std::vector< dataTy > &y, const std::string &modifiers, const std::string &name)
 Plot y vs. x data from vectors. More...
 
template<typename dataTx , typename dataTy >
int plot (const std::vector< dataTx > &x, const std::vector< dataTy > &y, const std::string &name)
 Plot y vs. x data from vectors. More...
 
template<typename dataTx , typename dataTy >
int plot (const std::vector< dataTx > &x, const std::vector< dataTy > &y)
 Plot y vs. x data from vectors. More...
 
template<typename dataTx , typename dataTy >
int point (dataTx x, dataTy y, const std::string &modifiers="", const std::string &title="")
 Plot a single point. More...
 
int circle (double xcen, double ycen, double radius, const std::string &modifiers="", const std::string &title="", int npoints=10)
 Draw a circle on the plot. More...
 
int circle (double radius, const std::string &modifiers="", const std::string &title="", int npoints=10)
 Draw a circle on the plot around the origin. More...
 
void clear ()
 Clear all the curves. More...
 
void reset ()
 Clear all the curves and reset plot configuration. More...
 
void listCurves ()
 List the curves and their specifications. More...
 
void modifiers (const std::string &name, const std::string &modifiers)
 Modify the modifiers for a curve. More...
 
void title (const std::string &name, const std::string &title)
 Modify the title for a curve. More...
 

Protected Member Functions

int plotImpl (const void *y, size_t Nbytes, const std::string &binary, const std::string &modifiers, const std::string &title, const std::string &name)
 Implementation of 1-D binary plotting. More...
 
int plotImpl (const void *x, const void *y, size_t Npts, size_t sizex, size_t sizey, const std::string &binaryx, const std::string &binaryy, const std::string &modifiers, const std::string &title, const std::string &name)
 Implementation of 2-d binary plotting. More...
 
int doPlotCommand ()
 Issue the plot command for all the curves. More...
 
FILE * openTempFile (char *fname)
 Open a temporary binary file, and provide the filename. More...
 

Protected Attributes

bool _gpError {false}
 Set to true if the response indicates a gnuplot error. More...
 
FILE * _pipeH {0}
 File stream for the gnuplot interface. More...
 
std::string _errLocation
 Where to create gnuplot stderr fifo. More...
 
std::string _errFName
 File name of the gnuplot stderr fifo. More...
 
int _errFD {0}
 File descriptor for the gnuplot stderr fifo. More...
 
std::string _tempLocation
 Location of temporary files. More...
 
std::vector< std::string > _tempFiles
 Vector of all temporary file names opened, used for removal on destruction. More...
 
bool _deleteTemp {true}
 Flag to control whether temporary files are deleted on destruction. Default is true (files deleted). More...
 

Member Function Documentation

◆ checkResponse()

int mx::math::gnuPlot::checkResponse ( std::string &  response,
double  timeout = 0 
)

Check for a response from gnuplot.

It typically takes some time for a response from gnuplot to become readable, whether an error occurs or not. It is often 0.3 seconds or more. If there is no error, there will be no response so waiting for a response to check for errors after every command can be very time consuming. Thus it is a choice whether to check for errors from gnuplot after every command, and what timeout to use.

Todo:
investigate having a second thread monitor for responses.

gnuplot terminates all outputs with \n\n, so this reads up to these two characters. It then strips any leading and trailing whitespace. If the response begins with gnuplot>, then the response is an error. In this case, checkResponse returns -1 and the gpError flag is set. If gpError is not set but the return value is -1, then some other error occurred (check errno).

Return values
0on timeout or successful read
-1on error, or if the gnuplot response indicates an error.
Parameters
[out]responsecontains the response from gnuplot, but is empty on timeout or error.
[in]timeout[optional] the length of time, in seconds, to wait for a response. Default is 0, but a minimum of 0.5 if a response is expected.

◆ circle() [1/2]

int mx::math::gnuPlot::circle ( double  radius,
const std::string &  modifiers = "",
const std::string &  title = "",
int  npoints = 10 
)

Draw a circle on the plot around the origin.

Creates a circle with radius and center (0,0), and plots it.

Parameters
[in]radiusthe circle radius
[in]modifiers[optional] contains any modifiers to the plot command other than binary, format, using, and title.
[in]title[optional] contains the title of the data set, default is an empty string and no key on the plot
[in]npoints[optional] specifies the number of points in each half circle. Default 10 is usually sufficient.

◆ circle() [2/2]

int mx::math::gnuPlot::circle ( double  xcen,
double  ycen,
double  radius,
const std::string &  modifiers = "",
const std::string &  title = "",
int  npoints = 10 
)

Draw a circle on the plot.

Creates a circle with specified center and radius, and plots it.

Parameters
[in]xcenthe x-coordinate of the circle center
[in]ycenthe y-coordinate of the circle center
[in]radiusthe circle radius
[in]modifiers[optional] contains any modifiers to the plot command other than binary, format, using, and title.
[in]title[optional] contains the title of the data set, default is an empty string and no key on the plot
[in]npoints[optional] specifies the number of points in each half circle. Default 10 is usually sufficient.

◆ clear()

void mx::math::gnuPlot::clear ( )

Clear all the curves.

◆ command()

int mx::math::gnuPlot::command ( const std::string &  com,
bool  flush = true 
)

Send a command to gnuplot.

The newline is appended to the command, and then it is sent to gnuplot.

Return values
0on success
-1on error
Parameters
[in]comthe command string
[in]flush[optional] if true (default), then the output stream is flushed once the command is written

Referenced by mx::math::eigenPseudoInverse().

◆ connect()

int mx::math::gnuPlot::connect ( )

Connect to gnuplot.

Spawns a gnuplot session using popen with stderr redirected to a temporary file. The temporary file is opened for reading.

Return values
0on success
-1on error

◆ doPlotCommand()

int mx::math::gnuPlot::doPlotCommand ( )
protected

Issue the plot command for all the curves.

◆ getResponse()

std::string mx::math::gnuPlot::getResponse ( const std::string &  com,
double  timeout = 0.5 
)

Get a response from gnuplot for a given command.

This should only be used if a response is expected.

Returns
"" (empty string) on timeout or error (errno and gpError() should be checked), and the response from gnuplot otherwise.
Parameters
[in]comthe command string
[in]timeoutthe length of time, in seconds, to wait for a response. Default is 0.5, which is the minimum that should be used.

◆ gpError()

bool mx::math::gnuPlot::gpError ( )

Return the value of the gpError flag.

This flag is set if gnuplot returns an error message (see checkResponse()). The error message can be accessed with gpErrorMsg().

Return values
0if no error
-1if an error has occurred.

◆ gpErrorMsg()

std::string mx::math::gnuPlot::gpErrorMsg ( )

Return the gnuplot error message.

The error message is extracted by checkResponse() when the response from gnuplot begins with "gnuplot>".

◆ listCurves()

void mx::math::gnuPlot::listCurves ( )

List the curves and their specifications.

◆ logx()

int mx::math::gnuPlot::logx ( )

Set the x axis to log scale.

Sends the command:

 set log x
Return values
0on success
-1on error

◆ logxy()

int mx::math::gnuPlot::logxy ( )

Set the x and y axes to log scale.

Sends the commands:

 set log x
 set log y
Return values
0on success
-1on error

◆ logy()

int mx::math::gnuPlot::logy ( )

Set the y axis to log scale.

Sends the command:

 set log y
Return values
0on success
-1on error

Referenced by mx::math::eigenPseudoInverse().

◆ modifiers()

void mx::math::gnuPlot::modifiers ( const std::string &  name,
const std::string &  modifiers 
)

Modify the modifiers for a curve.

Parameters
[in]namethe name of the curve
[in]modifiersthe new modifiers

Referenced by plot(), and point().

◆ openTempFile()

FILE* mx::math::gnuPlot::openTempFile ( char *  fname)
protected

Open a temporary binary file, and provide the filename.

◆ plot() [1/20]

template<typename dataT >
int mx::math::gnuPlot::plot ( const dataT *  y,
size_t  N 
)

Plot data from an array.

Copies the data in the array to a temporary binary file, and then forms the gnuplot plot command as follows:

*  plot "temp-file-name" binary format="%dataT" u 1 t ''
* 
Return values
0on success
-1on error
Parameters
[in]ya pointer to an array of data
[in]Nthe length of the array

Definition at line 882 of file gnuPlot.hpp.

References plotImpl().

◆ plot() [2/20]

template<typename dataT >
int mx::math::gnuPlot::plot ( const dataT *  y,
size_t  N,
const std::string &  modifiers,
const std::string &  name 
)

Plot data from an array.

Copies the data in the array to a temporary binary file, and then forms the gnuplot plot command as follows:

*  plot "temp-file-name" binary format="%dataT" u 1 t '' <modifiers>
* 

The modifiers string must NOT contain the binary, format, using, or the title modifiers, but can contain any other modifiers. Title is specified so that the name of the temporary file name is not printed on the plot.

Return values
0on success
-1on error
Parameters
[in]ya pointer to an array of data
[in]Nthe length of the array
[in]modifierscontains any modifiers to the plot command other than binary, format, using, and title.
[in]namethe identifying name of this curve

Definition at line 863 of file gnuPlot.hpp.

References modifiers(), and plotImpl().

◆ plot() [3/20]

template<typename dataT >
int mx::math::gnuPlot::plot ( const dataT *  y,
size_t  N,
const std::string &  modifiers,
const std::string &  title,
const std::string &  name 
)

Plot data from an array.

Copies the data in the array to a temporary binary file, and then forms the gnuplot plot command as follows:

*  plot "temp-file-name" binary format="%dataT" u 1 t "title" <modifiers>
* 

The modifiers string must NOT contain the binary, format, using, or the title modifiers, but can contain any other modifiers. Title is specified so that the name of the temporary file name is not printed on the plot.

Return values
0on success
-1on error
Parameters
[in]ya pointer to an array of data
[in]Nthe length of the array
[in]modifierscontains any modifiers to the plot command other than binary, format, using, and title.
[in]titlecontains the title of the data set, default is an empty string and no key on the plot
[in]namethe identifying name of this curve

Definition at line 852 of file gnuPlot.hpp.

References modifiers(), plotImpl(), and title().

◆ plot() [4/20]

template<typename dataT >
int mx::math::gnuPlot::plot ( const dataT *  y,
size_t  N,
const std::string &  name 
)

Plot data from an array.

Copies the data in the array to a temporary binary file, and then forms the gnuplot plot command as follows:

*  plot "temp-file-name" binary format="%dataT" u 1 t '' <modifiers>
* 
Return values
0on success
-1on error
Parameters
[in]ya pointer to an array of data
[in]Nthe length of the array
[in]namethe identifying name of this curve

Definition at line 873 of file gnuPlot.hpp.

References plotImpl().

◆ plot() [5/20]

template<typename dataTx , typename dataTy >
int mx::math::gnuPlot::plot ( const dataTx *  x,
const dataTy *  y,
size_t  N 
)

Plot y vs. x data from arrays.

Copies the data in the arrays to a temporary binary file, and then forms the gnuplot plot command as follows:

*  plot "temp-file-name" binary format="%dataTx%dataTy" u 1:2 t ''
* 
Return values
0on success
-1on error
Parameters
[in]xa pointer to an array of data for the independent variable
[in]ya pointer to an array of data for the dependent variable
[in]Nthe length of the arrays

Definition at line 957 of file gnuPlot.hpp.

References plotImpl().

◆ plot() [6/20]

template<typename dataTx , typename dataTy >
int mx::math::gnuPlot::plot ( const dataTx *  x,
const dataTy *  y,
size_t  N,
const std::string &  modifiers,
const std::string &  name 
)

Plot y vs. x data from arrays.

Copies the data in the arrays to a temporary binary file, and then forms the gnuplot plot command as follows:

*  plot "temp-file-name" binary format="%dataTx%dataTy" u 1:2 t '' <modifiers>
* 

The modifiers string must NOT contain the binary, format, using, or the title modifiers, but can contain any other modifiers. Title is specified so that the name of the temporary file name is not printed on the plot.

Return values
0on success
-1on error
Parameters
[in]xa pointer to an array of data for the independent variable
[in]ya pointer to an array of data for the dependent variable
[in]Nthe length of the arrays
[in]modifierscontains any modifiers to the plot command other than binary, format, using, and title.
[in]namethe identifying name of the curve

Definition at line 936 of file gnuPlot.hpp.

References modifiers(), and plotImpl().

◆ plot() [7/20]

template<typename dataTx , typename dataTy >
int mx::math::gnuPlot::plot ( const dataTx *  x,
const dataTy *  y,
size_t  N,
const std::string &  modifiers,
const std::string &  title,
const std::string &  name 
)

Plot y vs. x data from arrays.

Copies the data in the arrays to a temporary binary file, and then forms the gnuplot plot command as follows:

 plot "temp-file-name" binary format="%dataTx%dataTy" u 1:2 t "title" <modifiers>

The modifiers string must NOT contain the binary, format, using, or the title modifiers, but can contain any other modifiers. Title is specified so that the name of the temporary file name is not printed on the plot.

Return values
0on success
-1on error
Parameters
[in]xa pointer to an array of data for the independent variable
[in]ya pointer to an array of data for the dependent variable
[in]Nthe length of the arrays
[in]modifierscontains any modifiers to the plot command other than binary, format, using, and title.
[in]titlecontains the title of the data set
[in]namethe identifying name of the curve

Definition at line 924 of file gnuPlot.hpp.

References modifiers(), plotImpl(), and title().

◆ plot() [8/20]

template<typename dataTx , typename dataTy >
int mx::math::gnuPlot::plot ( const dataTx *  x,
const dataTy *  y,
size_t  N,
const std::string &  name 
)

Plot y vs. x data from arrays.

Copies the data in the arrays to a temporary binary file, and then forms the gnuplot plot command as follows:

*  plot "temp-file-name" binary format="%dataTx%dataTy" u 1:2 t ''
* 
Return values
0on success
-1on error
Parameters
[in]xa pointer to an array of data for the independent variable
[in]ya pointer to an array of data for the dependent variable
[in]Nthe length of the arrays
[in]namethe identifying name of the curve

Definition at line 947 of file gnuPlot.hpp.

References plotImpl().

◆ plot() [9/20]

int mx::math::gnuPlot::plot ( const std::string &  fname)

Plot from a file without specifying the name or any modifiers.

The file name is used for the identifying name

Forms the gnuplot plot command as follows:

* plot '<fname>' t ''
* 

The modifiers string can contain any modifiers such as using, etc. Should generally not include title.

Return values
0on success
-1on error

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
[in]fnamethe name (with full path) of the file containing data to plot

◆ plot() [10/20]

int mx::math::gnuPlot::plot ( const std::string &  fname,
const std::string &  modifiers,
const std::string &  name 
)

Plot from a file without specifying the title.

Forms the gnuplot plot command as follows:

* plot '<fname>' <modifiers> t ''
* 

The modifiers string can contain any modifiers such as using, etc. Should generally not include title.

Return values
0on success
-1on error

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
[in]fnamethe name (with full path) of the file containing data to plot
[in]modifierscontains any modifiers to the plot command.
[in]namethe name for this curve. If "" then the curve# is used.

◆ plot() [11/20]

int mx::math::gnuPlot::plot ( const std::string &  fname,
const std::string &  modifiers,
const std::string &  title,
const std::string &  name 
)

Plot from a file specifying all curve components.

Forms the gnuplot plot command as follows:

* plot '<fname>' <modifiers> t '<title>'
* 

The modifiers string can contain any modifiers such as using, etc. Should generally not include title.

Return values
0on success
-1on error
Parameters
[in]fnamethe name (with full path) of the file containing data to plot
[in]modifierscontains any modifiers to the plot command.
[in]titlethe title for this curve
[in]namethe name for this curve. If "" then curve# is used.

Referenced by mx::math::eigenPseudoInverse(), plot(), and point().

◆ plot() [12/20]

int mx::math::gnuPlot::plot ( const std::string &  fname,
const std::string &  name 
)

Plot from a file without modifiers.

The file name is used for the identifying name

Forms the gnuplot plot command as follows:

* plot '<fname>' <modifiers> t ''
* 

The modifiers string can contain any modifiers such as using, etc. Should generally not include title.

Return values
0on success
-1on error

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
[in]fnamethe name (with full path) of the file containing data to plot
[in]namethe name for this curve. If "" then the curve# is used

◆ plot() [13/20]

template<typename dataT >
int mx::math::gnuPlot::plot ( const std::vector< dataT > &  y)

Plot data from a vector.

Copies the data in the vector to a temporary binary file, and then forms the gnuplot plot command as follows:

*  plot "temp-file-name" binary format="%dataT" u 1 t '' 
* 
Return values
0on success
-1on error
Parameters
[in]ythe vector containing the data

Definition at line 917 of file gnuPlot.hpp.

◆ plot() [14/20]

template<typename dataT >
int mx::math::gnuPlot::plot ( const std::vector< dataT > &  y,
const std::string &  modifiers,
const std::string &  name 
)

Plot data from a vector.

Copies the data in the vector to a temporary binary file, and then forms the gnuplot plot command as follows:

*  plot "temp-file-name" binary format="%dataT" u 1 t '' <modifiers>
* 

The modifiers string must NOT contain the binary, format, using, or the title modifiers, but can contain any other modifiers. Title is specified so that the name of the temporary file name is not printed on the plot.

Return values
0on success
-1on error
Parameters
[in]ythe vector containing the data
[in]modifierscontains any modifiers to the plot command other than binary, format, using, and title.
[in]namethe identifying name of this curve

Definition at line 900 of file gnuPlot.hpp.

References modifiers().

◆ plot() [15/20]

template<typename dataT >
int mx::math::gnuPlot::plot ( const std::vector< dataT > &  y,
const std::string &  modifiers,
const std::string &  title,
const std::string &  name 
)

Plot data from a vector.

Copies the data in the vector to a temporary binary file, and then forms the gnuplot plot command as follows:

*  plot "temp-file-name" binary format="%dataT" u 1 t "title" <modifiers>
* 

The modifiers string must NOT contain the binary, format, using, or the title modifiers, but can contain any other modifiers. Title is specified so that the name of the temporary file name is not printed on the plot.

Return values
0on success
-1on error
Parameters
[in]ythe vector containing the data
[in]modifierscontains any modifiers to the plot command other than binary, format, using, and title.
[in]titlecontains the title of the data set, default is an empty string and no key on the plot
[in]namethe identifying name of this curve

Definition at line 890 of file gnuPlot.hpp.

References modifiers(), and title().

◆ plot() [16/20]

template<typename dataT >
int mx::math::gnuPlot::plot ( const std::vector< dataT > &  y,
const std::string &  name 
)

Plot data from a vector.

Copies the data in the vector to a temporary binary file, and then forms the gnuplot plot command as follows:

*  plot "temp-file-name" binary format="%dataT" u 1 t '' 
* 
Return values
0on success
-1on error
Parameters
[in]ythe vector containing the data
[in]namethe identifying name of this curve

Definition at line 909 of file gnuPlot.hpp.

◆ plot() [17/20]

template<typename dataTx , typename dataTy >
int mx::math::gnuPlot::plot ( const std::vector< dataTx > &  x,
const std::vector< dataTy > &  y 
)

Plot y vs. x data from vectors.

Copies the data in the vectors to a temporary binary file, and then forms the gnuplot plot command as follows:

*  plot "temp-file-name" binary format="%dataTx%dataTy" u 1:2 t ''
* 
Return values
0on success
-1on error
Parameters
[in]xa vector of data for the independent variable
[in]ya vector of data for the dependent variable

Definition at line 996 of file gnuPlot.hpp.

References plot().

◆ plot() [18/20]

template<typename dataTx , typename dataTy >
int mx::math::gnuPlot::plot ( const std::vector< dataTx > &  x,
const std::vector< dataTy > &  y,
const std::string &  modifiers,
const std::string &  name 
)

Plot y vs. x data from vectors.

Copies the data in the vectors to a temporary binary file, and then forms the gnuplot plot command as follows:

 plot "temp-file-name" binary format="%dataTx%dataTy" u 1:2 t '' <modifiers>

The modifiers string must NOT contain the binary, format, using, or the title modifiers, but can contain any other modifiers. Title is specified so that the name of the temporary file name is not printed on the plot.

Return values
0on success
-1on error
Parameters
[in]xa vector of data for the independent variable
[in]ya vector of data for the dependent variable
[in]modifierscontains any modifiers to the plot command other than binary, format, using, and title.
[in]namethe identifying name of the curve

Definition at line 977 of file gnuPlot.hpp.

References modifiers(), and plot().

◆ plot() [19/20]

template<typename dataTx , typename dataTy >
int mx::math::gnuPlot::plot ( const std::vector< dataTx > &  x,
const std::vector< dataTy > &  y,
const std::string &  modifiers,
const std::string &  title,
const std::string &  name 
)

Plot y vs. x data from vectors.

Copies the data in the vectors to a temporary binary file, and then forms the gnuplot plot command as follows:

 plot "temp-file-name" binary format="%dataTx%dataTy" u 1:2 t "title" <modifiers>

The modifiers string must NOT contain the binary, format, using, or the title modifiers, but can contain any other modifiers. Title is specified so that the name of the temporary file name is not printed on the plot.

Return values
0on success
-1on error
Parameters
[in]xa vector of data for the independent variable
[in]ya vector of data for the dependent variable
[in]modifierscontains any modifiers to the plot command other than binary, format, using, and title.
[in]titlecontains the title of the data set
[in]namethe identifying name of the curve

Definition at line 966 of file gnuPlot.hpp.

References modifiers(), plot(), and title().

◆ plot() [20/20]

template<typename dataTx , typename dataTy >
int mx::math::gnuPlot::plot ( const std::vector< dataTx > &  x,
const std::vector< dataTy > &  y,
const std::string &  name 
)

Plot y vs. x data from vectors.

Copies the data in the vectors to a temporary binary file, and then forms the gnuplot plot command as follows:

*  plot "temp-file-name" binary format="%dataTx%dataTy" u 1:2 t ''
* 
Return values
0on success
-1on error
Parameters
[in]xa vector of data for the independent variable
[in]ya vector of data for the dependent variable
[in]namethe identifying name of the curve

Definition at line 987 of file gnuPlot.hpp.

References plot().

◆ plotImpl() [1/2]

int mx::math::gnuPlot::plotImpl ( const void *  x,
const void *  y,
size_t  Npts,
size_t  sizex,
size_t  sizey,
const std::string &  binaryx,
const std::string &  binaryy,
const std::string &  modifiers,
const std::string &  title,
const std::string &  name 
)
protected

Implementation of 2-d binary plotting.

◆ plotImpl() [2/2]

int mx::math::gnuPlot::plotImpl ( const void *  y,
size_t  Nbytes,
const std::string &  binary,
const std::string &  modifiers,
const std::string &  title,
const std::string &  name 
)
protected

Implementation of 1-D binary plotting.

Referenced by plot().

◆ point()

template<typename dataTx , typename dataTy >
int mx::math::gnuPlot::point ( dataTx  x,
dataTy  y,
const std::string &  modifiers = "",
const std::string &  title = "" 
)

Plot a single point.

Copies the position as a length-1 vector to a temporary binary file, and then plots it.

Return values
0on success
-1on error
Parameters
[in]xthe independent axis (x) coordinate of the point
[in]ythe dependent axis (y) coordinate of the point
[in]modifiers[optional] contains any modifiers to the plot command other than binary, format, using, and title.
[in]title[optional] contains the title of the data set, default is an empty string and no key on the plot

Definition at line 1004 of file gnuPlot.hpp.

References modifiers(), plot(), and title().

◆ replot()

int mx::math::gnuPlot::replot ( )

Issue the replot command.

Return values
0on success
-1on error

◆ reset()

void mx::math::gnuPlot::reset ( )

Clear all the curves and reset plot configuration.

◆ title()

void mx::math::gnuPlot::title ( const std::string &  name,
const std::string &  title 
)

Modify the title for a curve.

Parameters
[in]namethe name of the curve
[in]titlethe new title

Referenced by plot(), and point().

◆ ulogx()

int mx::math::gnuPlot::ulogx ( )

Unset the x axis from log scale.

Sends the command:

 unset log x
Return values
0on success
-1on error

◆ ulogxy()

int mx::math::gnuPlot::ulogxy ( )

Unset the x and y axes from log scale.

Sends the command:

 unset log x
 unset log y
Return values
0on success
-1on error

◆ ulogy()

int mx::math::gnuPlot::ulogy ( )

Unset the y axis from log scale.

Sends the command:

 unset log y
Return values
0on success
-1on error

◆ xrange() [1/2]

int mx::math::gnuPlot::xrange ( )

Unset the x-axis range.

Sends the command:

* unset xrange
* 
Returns
0 on success
-1 on error

◆ xrange() [2/2]

int mx::math::gnuPlot::xrange ( double  x0,
double  x1 
)

Set the x-axis range.

Sends the command:

* set xrange [x0:x1]
* 
Returns
0 on success
-1 on error

◆ yrange() [1/2]

int mx::math::gnuPlot::yrange ( )

Unset the y-axis range.

Sends the command:

* unset yrange
* 
Returns
0 on success
-1 on error

◆ yrange() [2/2]

int mx::math::gnuPlot::yrange ( double  y0,
double  y1 
)

Set the y-axis range.

Sends the command:

* set yrange [y0:y1]
* 
Returns
0 on success
-1 on error

Member Data Documentation

◆ _deleteTemp

bool mx::math::gnuPlot::_deleteTemp {true}
protected

Flag to control whether temporary files are deleted on destruction. Default is true (files deleted).

Definition at line 225 of file gnuPlot.hpp.

◆ _errFD

int mx::math::gnuPlot::_errFD {0}
protected

File descriptor for the gnuplot stderr fifo.

Definition at line 214 of file gnuPlot.hpp.

◆ _errFName

std::string mx::math::gnuPlot::_errFName
protected

File name of the gnuplot stderr fifo.

Definition at line 211 of file gnuPlot.hpp.

◆ _errLocation

std::string mx::math::gnuPlot::_errLocation
protected

Where to create gnuplot stderr fifo.

Default is /dev/shm/

Definition at line 208 of file gnuPlot.hpp.

◆ _gpError

bool mx::math::gnuPlot::_gpError {false}
protected

Set to true if the response indicates a gnuplot error.

Definition at line 199 of file gnuPlot.hpp.

◆ _pipeH

FILE* mx::math::gnuPlot::_pipeH {0}
protected

File stream for the gnuplot interface.

Definition at line 203 of file gnuPlot.hpp.

◆ _tempFiles

std::vector<std::string> mx::math::gnuPlot::_tempFiles
protected

Vector of all temporary file names opened, used for removal on destruction.

Definition at line 222 of file gnuPlot.hpp.

◆ _tempLocation

std::string mx::math::gnuPlot::_tempLocation
protected

Location of temporary files.

Default is /dev/shm/

Definition at line 219 of file gnuPlot.hpp.


The documentation for this class was generated from the following file: