Axis

class JSL::Axis

An axis is a single instance of a plotting grid on the screen. Multiple such axes can exist simultaneously (via gnuplot::SetMultiplot()), with each axis tracking their own data and properties individually.

Public Functions

inline Axis()

Default, empty constructor (necessary for std::vector<Axis> to exist, even if never called)

inline Axis(std::string rootDir)

Expected constructor, generates a random id for itself, and generates a temporary directory in which it stores its data.

Parameters:

rootDir – The temporary folder generated by JSL::gnuplot, into which all temp data goes

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

Adds a line plot to the axis, plotting x against y, and using the args to define what the line looks like.

Parameters:
  • x – The x coordinates of the data to be plotted

  • y – The y coordinates of the data t be plotted, must be the same length as x

  • args – A variadic list of NameValuePair objects, used to define the properties of the line

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)

Adds a scatter plot to the axis, plotting x against y, and using the args to define what the line looks like.

Parameters:
  • x – The x coordinates of the data to be plotted

  • y – The y coordinates of the data t be plotted, must be the same length as x

  • args – A variadic list of NameValuePair objects, used to define the properties of the line

Returns:

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

inline std::string Show()

The command which generates the gnuplot scripting code for plotting the data on this axis.

Returns:

The string corresponding to the gnuplot script, must be written to file to be actionable

inline void SetXRange(double min, double max)

Simple setter for range_x.

Parameters:
  • min – The lower bound of the x range

  • max – The upper bound of the x range

inline void SetYRange(double min, double max)

Simple setter for Axis::range_y.

Parameters:
  • min – The lower bound of the y range

  • max – The upper bound of the y range

inline void SetXLabel(std::string xl)

Simple setter for Axis::xlabel.

inline void SetYLabel(std::string yl)

Simple setter for Axis::ylabel.

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

Setter for Axis::xlabel which also sets the font size of the axis text.

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

Setter for Axis::ylabel which also sets the font size of the axis text.

inline void SetXLog(bool val)

Simple setter for Axis::isLog_x.

inline void SetYLog(bool val)

Simple setter for Axis::isLog_y.

inline void SetLegend(bool state)

Simple setter for Axis::legendActive.

inline void SetTitle(std::string tit)

Simple setter for Axis::title.

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

Setter for Axis::title which also sets the fontsize for the title.

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

Sets the fontsize of one of the texts associated with the axis.

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

  • size – The desired fontsize

Private Functions

inline std::string NewData()

Called when data added to the axis. Increments the data counter, and generates a filename and file into which the plot data will be saved.

Returns:

The name of the file generated to store the data

inline void AddProperty(std::string line)

Used to add unique properties to Axis::WriteCommand during the Axis::Show() phase, followed by a linebreak.

Parameters:

line – A property to be written to file

inline void AddPlot(int i)

Called during Axis::Show(), writes the data associated with the i-th line to the Axis::WriteCommand.

Parameters:

i – The index of the data to be written

inline void LogSetter(const std::string &prefix, bool active)

Generates a string for either the x or y axis value of the logarithm toggle, which is then piped to Axis::AddProperty.

Parameters:
inline void RangeSetter(const std::string &axisPrefix, const std::vector<double> &range)

Generates a string for either the x or y axis value of the range, which is then piped to Axis::AddProperty.

Parameters:
  • prefix – Either “x” or “y”

  • active – Either value of Axis::xrange or Axis::yrange

Private Members

std::string title

The text which appears above the axis.

std::string xlabel

The text which appears underneath the x axis.

std::string ylabel

The text which appears to the left of the y axis.

std::vector<double> range_x

A (max) length-2 vector detailing the visual range of the plot on the x axis. If length is zero, uses gnuplot auto-scaling.

std::vector<double> range_y

A (max) length-2 vector detailing the visual range of the plot on the x axis. If length is zero, uses gnuplot auto-scaling.

bool isLog_x = false

If true, uses logarithmic scaling on the x axis.

bool isLog_y = false

If false, uses logarithmic scaling on the x axis.

int axisFontSize = -1

The font size used to write both the Axis::xlabel and Axis::ylabel (cannot be different for x/y). If < 0, uses the value of gnuplot::globalFontSize.

int titleFontSize = -1

The font size used to write Axis::title. If < 0, uses the value of gnuplot::globalFontSize.

int legendFontSize = -1

The font size used to write the legend, if active. If < 0, uses the value of gnuplot::globalFontSize.

std::string DataDir

The directory reserved for this axis to write its data to file for gnuplot to later scoop up.

std::vector<PlotData> Data

A vector of data detailing what should be plotted, and what it looks like, accessed during Axis::Show()

bool legendActive = false

If true, shows a legend on the axis.

int DataIdx

The current counter for how many plots/lines have been added to the axis, used to index Axis::Data.

std::string WriteCommand

The string into which the Axis::Show() function puts all its data.