Gtkmm-PLplot 3.0
A scientific plotting library for Gtkmm
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Private Member Functions | List of all members
Gtk::PLplot::PlotData2D Class Reference

a class that will hold a single dataset and its properties for a Plot2D plot More...

#include <gtkmm-plplot/plotdata2d.h>

Inheritance diagram for Gtk::PLplot::PlotData2D:
Inheritance graph
[legend]

Public Member Functions

 PlotData2D (const std::vector< double > &x, const std::vector< double > &y, Gdk::RGBA color=Gdk::RGBA("red"), LineStyle line_style=CONTINUOUS, double line_width=PLOTDATA_DEFAULT_LINE_WIDTH)
 
 PlotData2D (const std::valarray< double > &x, const std::valarray< double > &y, Gdk::RGBA color=Gdk::RGBA("red"), LineStyle line_style=CONTINUOUS, double line_width=PLOTDATA_DEFAULT_LINE_WIDTH)
 
 PlotData2D (const std::vector< double > &y, Gdk::RGBA color=Gdk::RGBA("red"), LineStyle line_style=CONTINUOUS, double line_width=PLOTDATA_DEFAULT_LINE_WIDTH)
 
 PlotData2D (const std::valarray< double > &y, Gdk::RGBA color=Gdk::RGBA("red"), LineStyle line_style=CONTINUOUS, double line_width=PLOTDATA_DEFAULT_LINE_WIDTH)
 
virtual ~PlotData2D ()
 
std::vector< double > get_vector_x ()
 
std::vector< double > get_vector_y ()
 
size_t size ()
 
virtual void get_extremes (double &xmin, double &xmax, double &ymin, double &ymax)
 
void set_symbol (Glib::ustring symbol)
 
Glib::ustring get_symbol ()
 
void set_symbol_color (Gdk::RGBA color)
 
Gdk::RGBA get_symbol_color ()
 
void set_symbol_height_scale_factor (double scale_factor=1.0)
 
double get_symbol_height_scale_factor ()
 
virtual void add_datapoint (double xval, double yval)
 
virtual void add_datapoint (std::pair< double, double > xy_pair)
 
virtual void remove_datapoint (size_t index)
 
virtual void replace_datapoints (const std::vector< double > &x, const std::vector< double > &y)
 
virtual void replace_datapoints (const std::valarray< double > &x, const std::valarray< double > &y)
 
virtual void draw_plot_data (const Cairo::RefPtr< Cairo::Context > &cr, plstream *pls) override
 
- Public Member Functions inherited from Gtk::PLplot::PlotDataLine
virtual ~PlotDataLine ()
 
void set_color (Gdk::RGBA color)
 
Gdk::RGBA get_color ()
 
void set_line_style (LineStyle line_style)
 
LineStyle get_line_style ()
 
void set_line_width (double line_width)
 
double get_line_width ()
 
- Public Member Functions inherited from Gtk::PLplot::PlotData
virtual ~PlotData ()
 
void set_name (Glib::ustring name)
 
Glib::ustring get_name ()
 
void show ()
 
void hide ()
 
bool is_showing () const
 
sigc::signal< void(void)> signal_changed ()
 
sigc::signal< void(void)> signal_data_modified ()
 
- Public Member Functions inherited from Gtk::PLplot::Object
virtual void set_manage ()
 

Protected Attributes

std::vector< double > x
 The X-values of the dataset.
 
std::vector< double > y
 The Y-values of the dataset.
 
Glib::ustring symbol
 If not an empty string, the symbol will be plotted at each of the data points from x and y.
 
Gdk::RGBA symbol_color
 The color the symbol will be plotted in.
 
double symbol_scale_factor
 Scale factor that will determine the size of the symbols. Default is 1.
 
- Protected Attributes inherited from Gtk::PLplot::PlotDataLine
Gdk::RGBA color
 The color the dataset will be drawn in.
 
LineStyle line_style
 The linestyle that will be used for this dataset in the plot.
 
double line_width
 The line width of the dataset. Default is 1.0.
 
- Protected Attributes inherited from Gtk::PLplot::PlotData
sigc::signal< void(void)> _signal_changed
 signal that gets emitted whenever any of the dataset proprties is changed.
 
sigc::signal< void(void)> _signal_data_modified
 signal that gets emitted whenever the X- and Y-datasets have been modified.
 

Private Member Functions

 PlotData2D ()=delete
 no default constructor
 
PlotData2Doperator= (const PlotData2D &)=delete
 no assignment operator
 
 PlotData2D (const PlotData2D &source)=delete
 no default copy constructor;
 

Additional Inherited Members

- Protected Member Functions inherited from Gtk::PLplot::PlotDataLine
 PlotDataLine (Gdk::RGBA color, LineStyle line_style, double line_width)
 
- Protected Member Functions inherited from Gtk::PLplot::PlotData
virtual void on_changed ()
 
virtual void on_data_modified ()
 
 PlotData ()
 
- Protected Member Functions inherited from Gtk::PLplot::Object
 Object ()
 

Detailed Description

a class that will hold a single dataset and its properties for a Plot2D plot

Instances of this class contain a single dataset for a Plot2D two-dimensional plot, consisting of the raw X- and Y-data, along with a number of properties that will determine the appearance of the plot. Data may be represented as a line, symbols or both. The constructors of this class allow to use either std::vector or std::valarray as sources of data, for added flexibility. Internally they are stored only as std::vector though. Important is that whenever a property is changed, signal_changed() is emitted, which will eventually be picked up by the canvas that will hold the plot. Several of the methods that are offered by this class are demonstrated in Example 5: Mixing plot lines and symbols plus adding datapoints

Constructor & Destructor Documentation

◆ PlotData2D() [1/6]

Gtk::PLplot::PlotData2D::PlotData2D ( )
privatedelete

no default constructor

◆ PlotData2D() [2/6]

Gtk::PLplot::PlotData2D::PlotData2D ( const PlotData2D source)
privatedelete

no default copy constructor;

◆ PlotData2D() [3/6]

Gtk::PLplot::PlotData2D::PlotData2D ( const std::vector< double > &  x,
const std::vector< double > &  y,
Gdk::RGBA  color = Gdk::RGBA("red"),
LineStyle  line_style = CONTINUOUS,
double  line_width = PLOTDATA_DEFAULT_LINE_WIDTH 
)

Constructor

This constructor initializes a new dataset using two vectors, one for the X-values, and one for the Y-values. Optionally, one can also use the constructor to override the default color, line style and line width.

Parameters
xthe X-values, as std::vector
ythe Y-values, as std::vector
colorthe line color, default is red
line_stylethe line style, default is CONTINUOUS
line_widththe line width, default is 1.0
Exceptions
Gtk::PLplot::Exception

◆ PlotData2D() [4/6]

Gtk::PLplot::PlotData2D::PlotData2D ( const std::valarray< double > &  x,
const std::valarray< double > &  y,
Gdk::RGBA  color = Gdk::RGBA("red"),
LineStyle  line_style = CONTINUOUS,
double  line_width = PLOTDATA_DEFAULT_LINE_WIDTH 
)

Constructor

This constructor initializes a new dataset using two valarrays, one for the X-values, and one for the Y-values. Optionally, one can also use the constructor to override the default color, line style and line width.

Parameters
xthe X-values, as std::valarray
ythe Y-values, as std::valarray
colorthe line color, default is red
line_stylethe line style, default is CONTINUOUS
line_widththe line width, default is 1.0

◆ PlotData2D() [5/6]

Gtk::PLplot::PlotData2D::PlotData2D ( const std::vector< double > &  y,
Gdk::RGBA  color = Gdk::RGBA("red"),
LineStyle  line_style = CONTINUOUS,
double  line_width = PLOTDATA_DEFAULT_LINE_WIDTH 
)

Constructor

This constructor initializes a new dataset using a single vector for the Y-values. The X-values will be set to a vector of the same size with elements set to correspond to their array subscript. Optionally, one can also use the constructor to override the default color, line style and line width.

Parameters
ythe Y-values, as std::vector
colorthe line color, default is red
line_stylethe line style, default is CONTINUOUS
line_widththe line width, default is 1.0

◆ PlotData2D() [6/6]

Gtk::PLplot::PlotData2D::PlotData2D ( const std::valarray< double > &  y,
Gdk::RGBA  color = Gdk::RGBA("red"),
LineStyle  line_style = CONTINUOUS,
double  line_width = PLOTDATA_DEFAULT_LINE_WIDTH 
)

Constructor

This constructor initializes a new dataset using a single valarray for the Y-values. The X-values will be set to a vector of the same size with elements set to correspond to their array subscript. Optionally, one can also use the constructor to override the default color, line style and line width.

Parameters
ythe Y-values, as std::valarray
colorthe line color, default is red
line_stylethe line style, default is CONTINUOUS
line_widththe line width, default is 1.0

◆ ~PlotData2D()

virtual Gtk::PLplot::PlotData2D::~PlotData2D ( )
virtual

Destructor

Member Function Documentation

◆ add_datapoint() [1/2]

virtual void Gtk::PLplot::PlotData2D::add_datapoint ( double  xval,
double  yval 
)
virtual

Add a single datapoint, consisting of an xval and yval value, to the dataset

This datapoint will be added at the end of the std::vector's x and y. After this method is called, the plot will be automatically updated to reflect the changes.

Parameters
xvalan X-value
yvalan Y-value

Reimplemented in Gtk::PLplot::PlotData2DErrorXY, Gtk::PLplot::PlotData3D, Gtk::PLplot::PlotData2DErrorX, and Gtk::PLplot::PlotData2DErrorY.

◆ add_datapoint() [2/2]

virtual void Gtk::PLplot::PlotData2D::add_datapoint ( std::pair< double, double >  xy_pair)
virtual

Add a single datapoint, consisting of a std::pair with an X and Y value, to the dataset

This datapoint will be added at the end of the std::vector's x and y. After this method is called, the plot will be automatically updated to reflect the changes.

Parameters
xy_paira std::pair containing both an X- and a Y- value

Reimplemented in Gtk::PLplot::PlotData2DErrorXY, Gtk::PLplot::PlotData3D, Gtk::PLplot::PlotData2DErrorX, and Gtk::PLplot::PlotData2DErrorY.

◆ draw_plot_data()

virtual void Gtk::PLplot::PlotData2D::draw_plot_data ( const Cairo::RefPtr< Cairo::Context > &  cr,
plstream *  pls 
)
overridevirtual

Method to draw the dataset

This method is virtual allowing inheriting classes to implement their own method with the same signature.

Parameters
crthe cairo context to draw to.
plsthe PLplot plstream object that will do the actual plotting on the Cairo context

Reimplemented from Gtk::PLplot::PlotData.

Reimplemented in Gtk::PLplot::PlotData2DErrorX, Gtk::PLplot::PlotData2DErrorXY, Gtk::PLplot::PlotData2DErrorY, and Gtk::PLplot::PlotData3D.

◆ get_extremes()

virtual void Gtk::PLplot::PlotData2D::get_extremes ( double &  xmin,
double &  xmax,
double &  ymin,
double &  ymax 
)
virtual

Get the data extremes: minima and maxima along both X- and Y-axes

Parameters
xminX minimum value
xmaxX maximum value
yminY minimum value
ymaxY minimum value

Reimplemented in Gtk::PLplot::PlotData2DErrorX, Gtk::PLplot::PlotData2DErrorXY, and Gtk::PLplot::PlotData2DErrorY.

◆ get_symbol()

Glib::ustring Gtk::PLplot::PlotData2D::get_symbol ( )

Get the plot symbol

See set_symbol() for more information

Returns
the symbol currently to be used for plotting

◆ get_symbol_color()

Gdk::RGBA Gtk::PLplot::PlotData2D::get_symbol_color ( )

Get the plot symbol color

See set_symbol() for more information about plotting symbols

Returns
the color that is currently used for plotting symbols

◆ get_symbol_height_scale_factor()

double Gtk::PLplot::PlotData2D::get_symbol_height_scale_factor ( )

Get the plot symbol height scale factor

See set_symbol() for more information about plotting symbols

Returns
the current scale factor that will used to determine the height of the plotting symbols.
Exceptions
Gtk::PLplot::Exception

◆ get_vector_x()

std::vector< double > Gtk::PLplot::PlotData2D::get_vector_x ( )
Returns
a copy of the dataset X-values

◆ get_vector_y()

std::vector< double > Gtk::PLplot::PlotData2D::get_vector_y ( )
Returns
a copy of the dataset Y-values

◆ operator=()

PlotData2D & Gtk::PLplot::PlotData2D::operator= ( const PlotData2D )
privatedelete

no assignment operator

◆ remove_datapoint()

virtual void Gtk::PLplot::PlotData2D::remove_datapoint ( size_t  index)
virtual

Removes a single datapoint from the dataset.

The datapoint at position index will be removed from the dataset if index is valid. An exception will be thrown otherwise. After this method is called, the plot will be automatically updated to reflect the changes.

Parameters
indexThe current position of the datapoint in the dataset.
Exceptions
Gtk::PLplot::Exception

Reimplemented in Gtk::PLplot::PlotData2DErrorX, Gtk::PLplot::PlotData2DErrorXY, Gtk::PLplot::PlotData2DErrorY, and Gtk::PLplot::PlotData3D.

◆ replace_datapoints() [1/2]

virtual void Gtk::PLplot::PlotData2D::replace_datapoints ( const std::valarray< double > &  x,
const std::valarray< double > &  y 
)
virtual

Replaces all datapoints in the dataset with the new valarrays

This method assumes that x and y are valarrays of equal length. An exception will be thrown otherwise. After this method is called, the plot will be automatically updated to reflect the changes.

Parameters
xThe new X-values, as std::valarray<double>
yThe new Y-values, as std::valarray<double>
Exceptions
Gtk::PLplot::Exception

Reimplemented in Gtk::PLplot::PlotData2DErrorXY, Gtk::PLplot::PlotData2DErrorX, Gtk::PLplot::PlotData2DErrorY, and Gtk::PLplot::PlotData3D.

◆ replace_datapoints() [2/2]

virtual void Gtk::PLplot::PlotData2D::replace_datapoints ( const std::vector< double > &  x,
const std::vector< double > &  y 
)
virtual

Replaces all datapoints in the dataset with the new vectors

This method assumes that x and y are vectors of equal length. An exception will be thrown otherwise. After this method is called, the plot will be automatically updated to reflect the changes.

Parameters
xThe new X-values, as std::vector<double>
yThe new Y-values, as std::vector<double>
Exceptions
Gtk::PLplot::Exception

Reimplemented in Gtk::PLplot::PlotData2DErrorXY, Gtk::PLplot::PlotData2DErrorX, Gtk::PLplot::PlotData2DErrorY, and Gtk::PLplot::PlotData3D.

◆ set_symbol()

void Gtk::PLplot::PlotData2D::set_symbol ( Glib::ustring  symbol)

Set the plot symbol

It is possible to plot a symbol (string) at the datapoints, either replacing (if line_style is NONE) or complementing the line connecting the points. The symbol will be sent 'as-is' to PLplot, meaning that it supports the many escape-sequences that PLplot provides. For more information, the reader is referred to the PLplot manual, section 3.8.4 Escape sequences in text. If the plot symbol is no longer desired, disable it by passing an emptry string.

Parameters
symbolthe symbol to be used for plotting

◆ set_symbol_color()

void Gtk::PLplot::PlotData2D::set_symbol_color ( Gdk::RGBA  color)

Set the plot symbol color

See set_symbol() for more information about plotting symbols

Parameters
colorthe color that will used for plotting the symbols

◆ set_symbol_height_scale_factor()

void Gtk::PLplot::PlotData2D::set_symbol_height_scale_factor ( double  scale_factor = 1.0)

Set the plot symbol height scale factor

See set_symbol() for more information about plotting symbols

Parameters
scale_factorthe scale factor that will used to determine the height of the plotting symbols.

◆ size()

size_t Gtk::PLplot::PlotData2D::size ( )
Returns
the number of elements in the dataset

Member Data Documentation

◆ symbol

Glib::ustring Gtk::PLplot::PlotData2D::symbol
protected

If not an empty string, the symbol will be plotted at each of the data points from x and y.

◆ symbol_color

Gdk::RGBA Gtk::PLplot::PlotData2D::symbol_color
protected

The color the symbol will be plotted in.

◆ symbol_scale_factor

double Gtk::PLplot::PlotData2D::symbol_scale_factor
protected

Scale factor that will determine the size of the symbols. Default is 1.

◆ x

std::vector<double> Gtk::PLplot::PlotData2D::x
protected

The X-values of the dataset.

◆ y

std::vector<double> Gtk::PLplot::PlotData2D::y
protected

The Y-values of the dataset.