gnuplot Object

The main point of contact for the gnuplot interface is through the JSL::gnuplot class.

class JSL::gnuplot

The global interface for the plotting system. All calls should be piped through this individual class. Each gnuplot object corresponds to a single plot (though they might have severable axes within each plot)

Public Functions

inline gnuplot()

Constructor function, generates a unique name for itself, and creates a directory into which it stores its own data.

inline ~gnuplot()

Custom destructor which also calls CleanupTempFiles, tidying up after itself.

inline void SetMultiplot(int yCount, int xCount)

Puts gnuplot into multiplot mode, with yCount rows and xCount columns. Whenever this function is called, the entire set of axes is wiped clean.

Parameters:
  • yCount – The number of rows

  • xCount

inline void SetAxis(unsigned int y, unsigned int x)

Sets the current axis focus to the y-th row and x-th column. The “axis in focus” is acted upon whenever the gnuplot object is given a command (i.e. gnuplot::Plot) which does not otherwise specify the axis. By “switching focus”, calling gnuplot::Plot will write on different axes. It is also possible to act on the axes directly, using the operator[] overload, i.e. gnuplot[i][j].Plot() would produce the same output as gnuplot.SetAxis(i,j); Plot() - though with the second version, a subsequent call to Scatter() would be written to the same axis, which would not be guaranteed for the first case.

inline void SetAxis(int idx)

Sets the current axis focus to the idx-th axis, numbering columns-then-rows.

template<class T, class S, typename ...Ts>
inline PlotData &Plot(const std::vector<T> &x, const std::vector<S> &y, NameValuePair<Ts>... args)

Passes the arguments along to the Axis::Plot() function associated with the current axis focus.

Returns:

A reference to the generated JSL::PlotData object, allowing for post-facto modification of the linestyle.

template<class T, class S, typename ...Ts>
inline PlotData &Plot(const T &x, const S &y, NameValuePair<Ts>... args)

As with Plot(const std::vector<T> & x,const std::vector<S> & y, NameValuePair<Ts>… args), but permits non-vector objects which can still be cast into vectors (i.e. JSL::Vector objects)

Returns:

A reference to the generated JSL::PlotData object, allowing for post-facto modification of the linestyle.

template<class T, class S, typename ...Ts>
inline PlotData &Scatter(const std::vector<T> &x, const std::vector<S> &y, NameValuePair<Ts>... args)

Passes the arguments along to the Axis::Scatter() function associated with the current axis focus.

Returns:

A reference to the generated JSL::PlotData object, allowing for post-facto modification of the linestyle.

template<class T, class S, typename ...Ts>
inline PlotData &Scatter(const T &x, const S &y, NameValuePair<Ts>... args)

As with Scatter(const std::vector<T> & x,const std::vector<S> & y, NameValuePair<Ts>… args), but permits non-vector objects which can still be cast into vectors (i.e. JSL::Vector objects)

Returns:

A reference to the generated JSL::PlotData object, allowing for post-facto modification of the linestyle.

inline void Show()

The key function - until this function is called, the plot is hypothetical. Calling this function generates a gnuplot script file, which each axis writes to to generate the appropriate plot, which is then called using a system command, producing the plot.

inline std::vector<Axis> &operator[](int i)

Allows indexing into the Axes without using the SetAxis(int,int) function, accessing the Axis object directly. Note that this returns a vector of axis objects, hence access must be via gunplot[i][j].

inline void SetXRange(double min, double max)

Calls Axis::SetXRange(double,double) on the axis currently in focus.

inline void SetYRange(double min, double max)

Calls Axis::SetYRange(double,double) on the axis currently in focus.

inline void SetXLog(bool val)

Calls Axis::SetXLog on the axis currently in focus.

inline void SetYLog(bool val)

Calls Axis::SetYLog on the axis currently in focus.

inline void SetXLabel(std::string xl)

Calls Axis::SetXLabel(std::string) on the axis currently in focus.

inline void SetYLabel(std::string yl)

Calls Axis::SetYLabel(std::string) on the axis currently in focus.

inline void SetXLabel(std::string xl, int size)

Calls Axis::SetXLabel(std::string,int) on the axis currently in focus.

inline void SetYLabel(std::string yl, int size)

Calls Axis::SetYLabel(std::string,int) on the axis currently in focus.

inline void SetLegend(bool state)

Calls Axis::SetLegend on the axis currently in focus.

inline void WindowSize(int width, int height)

Changes the window size of the generated plot, measured in pixels.

inline void SetTitle(std::string tit)

Calls Axis::SetTitle(std::string) on the axis currently in focus.

inline void SetTitle(std::string tit, int size)

Calls Axis::SetTitle(std::string,int) on the axis currently in focus.

inline void SetSuperTitle(std::string tit)

Simple setter for gnuplot::superTitle.

inline void SetSuperTitle(std::string tit, int size)

Simple setter for gnuplot::superTitle, and changes the font size it is written to.

inline void SetTerminal(std::string t)

Simple setter for gnuplot::terminal.

inline void SetOutput(std::string out)

Simple setter for gnuplot::output.

inline void SetFont(std::string f)

Simple setter for gnuplot::font.

inline void SetFontSize(Fonts::Target target, unsigned int size)

Sets the fontsize of one of the texts associated with either the global fonts (such as global default or supertitle), or of the axis currently in focus.

Parameters:
  • target – The identifier of the text to be changed

  • size – The desired fontsize

Private Functions

inline void CleanupTempFiles()

Current value of the window height.

When called, and if the relevant compiler flag is not set, recursively deletes the directory associated with gnuplot::DirName

inline void InitialiseOutput(std::string outName)

Prints a default message and begins the setup of the gnuplot script.

Parameters:

outName – the name of the gnuplot script

inline void WriteMultiplotToFile(std::string gpFile)

Writes the data associated with the multiplot information to file.

Private Members

std::string superTitle = "__null__"

In multiplot mode, the supertitle appears above all other axis titles.

std::vector<std::vector<Axis>> Axes

The array of JSL::Axis objects containing the relevant plot data.

std::string DirName

The temporary directory name created for this gnuplot object.

int axis_x

The current x position of the axis in focus.

int axis_y

The current y position of the axis in focus.

int axis_x_max = 0

The maximum permitted value of gnuplot::axis_x.

int axis_y_max = 0

The maximum permitted value of gnuplot::axis_y.

int axisCount = 1

The current number of axes on the figure.

std::string terminal = "qt"

The current gnuplot terminal mode. See gnuplot documentation for more details.

std::string output = "__null__"

The current output file that gnuplot will try to save to, if the terminal permits it. If set to null, this argument is ignored.

std::string font = "Geneva"

The current global font used by the terminal.

int globalFontSize = 14
int superTitleFontSize = -1

< The global font size, which is used unless otherwise specified by a SetFontSize call

The font size assigned to gnuplot::superTitle. If < 0, uses the value of gnuplot::globalFontSize

bool defaultSize = true
int windowWidth

Toggle indicating that gnuplot::WindowSize() has not been called &#8212; needed because changing window size is gross in gnuplot, so best left alone!

int windowHeight

Current value of the window Width.