SigPack - the C++ signal processing library
sp::gplot Class Reference

#include <gplot.h>

Collaboration diagram for sp::gplot:
Collaboration graph

Classes

struct  plot_data_s
 

Public Member Functions

 gplot ()
 
 ~gplot ()
 
void send2gp (const char *cmdstr)
 
void flush_cmd_buf (void)
 
void draw_now (void)
 
void figure (const int fig)
 
void window (const int fig, const char *name, const int x, const int y, const int width, const int height)
 
void window (const char *name, const int x, const int y, const int width, const int height)
 
void close_window (void)
 
void grid_on (void)
 
void grid_off (void)
 
void xlabel (const char *label)
 
void ylabel (const char *label)
 
void label (const double &x, const double &y, const char *label)
 
void title (const char *name)
 
void xlim (const double xmin, const double xmax)
 
void ylim (const double ymin, const double ymax)
 
template<typename T1 , typename T2 >
void plot_add (const T1 &x, const T2 &y, const std::string lb, const std::string ls="lines")
 
template<typename T1 >
void plot_add (const T1 &y, const std::string lb, const std::string ls="lines")
 
void plot_add_mat (const arma::mat &y)
 
void plot_add_mat (const arma::mat &y, const std::string p_lb)
 
void plot_show (void)
 
void plot_clear (void)
 
template<typename T >
void fast_plot (const arma::Col< T > &x, const std::string fmt_args="with lines")
 
template<typename T >
void fast_plot (const arma::Col< T > &x, const arma::Col< T > &y, const std::string fmt_args="with lines")
 
template<typename T >
void image (const arma::Mat< T > &x)
 
template<typename T >
void image (const arma::Cube< T > &x)
 
template<typename T >
void mesh (const arma::Mat< T > &x)
 
template<typename T >
void surf (const arma::Mat< T > &x)
 
void set_parula_line (void)
 
void set_jet_line (void)
 
void set_set1_line (void)
 
void set_jet_palette (void)
 
void set_parula_palette (void)
 
void set_coolwarm_palette (void)
 
void set_blackbody_palette (void)
 
void set_output (const char *name)
 
void reset_term (void)
 
void set_term (const char *ttype)
 

Private Member Functions

template<typename T1 , typename T2 >
void plot_str2 (const T1 &x, const T2 &y)
 
template<typename T >
std::string get_type (T x)
 

Private Attributes

FILE * gnucmd
 
std::string term
 
int fig_ix
 
int plot_ix
 
std::vector< plot_data_splotlist
 

Detailed Description

Implements a class for streaming data to Gnuplot using a pipe. Inspiration from https://code.google.com/p/gnuplot-cpp/

Requires Gnuplot version > 5.0

Note
In Windows only one class is allowed. Using multiple figures are controlled by a figure number. In Linux we may use one instance per figure.
Examples:
adaptive_filter.cpp, filter_plot.cpp, image.cpp, kalman_linear.cpp, kalman_UKF.cpp, latex.cpp, and spectrum.cpp.

Definition at line 25 of file gplot.h.

Constructor & Destructor Documentation

◆ gplot()

sp::gplot::gplot ( )
inline

Constructor.

Opens a pipe to gnuplot program. Make sure it is found/accessable by the system.

Definition at line 102 of file gplot.h.

References err_handler.

◆ ~gplot()

sp::gplot::~gplot ( )
inline

Destructor.

Definition at line 128 of file gplot.h.

Member Function Documentation

◆ close_window()

void sp::gplot::close_window ( void  )
inline

Close window.

Definition at line 213 of file gplot.h.

References send2gp().

Here is the call graph for this function:

◆ draw_now()

void sp::gplot::draw_now ( void  )
inline

Updates gnuplot instantly. (Flushes the command buffer)

Definition at line 157 of file gplot.h.

◆ fast_plot() [1/2]

template<typename T >
void sp::gplot::fast_plot ( const arma::Col< T > &  x,
const std::string  fmt_args = "with lines" 
)
inline

Plot vector, fast version.

Parameters
xx vector

Definition at line 426 of file gplot.h.

References flush_cmd_buf(), get_type(), and send2gp().

Here is the call graph for this function:

◆ fast_plot() [2/2]

template<typename T >
void sp::gplot::fast_plot ( const arma::Col< T > &  x,
const arma::Col< T > &  y,
const std::string  fmt_args = "with lines" 
)
inline

Plot vector, fast version.

x and y needs to have the same type

Parameters
xx vector
yy vector

Definition at line 448 of file gplot.h.

References flush_cmd_buf(), get_type(), and send2gp().

Here is the call graph for this function:

◆ figure()

void sp::gplot::figure ( const int  fig)
inline

Sets the active figure.

Parameters
figFigure number

Definition at line 163 of file gplot.h.

References send2gp().

Here is the call graph for this function:

◆ flush_cmd_buf()

void sp::gplot::flush_cmd_buf ( void  )
inline

Flush command buffer to Gnuplot pipe.

Definition at line 152 of file gplot.h.

Referenced by fast_plot(), image(), and mesh().

◆ get_type()

template<typename T >
std::string sp::gplot::get_type ( x)
inlineprivate

Get type.

Parameters
xx input type
Returns
Type name

Definition at line 66 of file gplot.h.

References err_handler.

Referenced by fast_plot(), image(), and mesh().

◆ grid_off()

void sp::gplot::grid_off ( void  )
inline

Set grid.

Definition at line 230 of file gplot.h.

References send2gp().

Here is the call graph for this function:

◆ grid_on()

void sp::gplot::grid_on ( void  )
inline

Set grid.

Examples:
filter_plot.cpp.

Definition at line 225 of file gplot.h.

References send2gp().

Referenced by main().

Here is the call graph for this function:

◆ image() [1/2]

template<typename T >
void sp::gplot::image ( const arma::Mat< T > &  x)
inline

Plot mat as image.

Parameters
xx matrix
Examples:
image.cpp, and spectrum.cpp.

Definition at line 473 of file gplot.h.

References flush_cmd_buf(), get_type(), send2gp(), xlim(), and ylim().

Referenced by main().

Here is the call graph for this function:

◆ image() [2/2]

template<typename T >
void sp::gplot::image ( const arma::Cube< T > &  x)
inline

Plot cube as image.

Parameters
xx matrix (R,G,B)

Definition at line 492 of file gplot.h.

References flush_cmd_buf(), get_type(), send2gp(), xlim(), and ylim().

Here is the call graph for this function:

◆ label()

void sp::gplot::label ( const double &  x,
const double &  y,
const char *  label 
)
inline

Set label at position x,y.

Parameters
xx value
yy value
labellabel string
Examples:
latex.cpp.

Definition at line 262 of file gplot.h.

References send2gp().

Referenced by main().

Here is the call graph for this function:

◆ mesh()

template<typename T >
void sp::gplot::mesh ( const arma::Mat< T > &  x)
inline

Plot mat as mesh.

Parameters
xx matrix

Definition at line 524 of file gplot.h.

References flush_cmd_buf(), get_type(), and send2gp().

Referenced by surf().

Here is the call graph for this function:

◆ plot_add() [1/2]

template<typename T1 , typename T2 >
void sp::gplot::plot_add ( const T1 &  x,
const T2 &  y,
const std::string  lb,
const std::string  ls = "lines" 
)
inline

Push plot y vs. x with label and linespec.

Parameters
xx vector
yy vector
lblabel
lsline spec
Examples:
adaptive_filter.cpp, filter_plot.cpp, kalman_linear.cpp, kalman_UKF.cpp, and latex.cpp.

Definition at line 316 of file gplot.h.

References sp::gplot::plot_data_s::label, sp::gplot::plot_data_s::linespec, and plot_str2().

Referenced by main().

Here is the call graph for this function:

◆ plot_add() [2/2]

template<typename T1 >
void sp::gplot::plot_add ( const T1 &  y,
const std::string  lb,
const std::string  ls = "lines" 
)
inline

Push plot y vs. x with label and linespec.

Parameters
yy vector
lblabel
lsline spec

Definition at line 336 of file gplot.h.

References sp::gplot::plot_data_s::label, sp::gplot::plot_data_s::linespec, and plot_str2().

Here is the call graph for this function:

◆ plot_add_mat() [1/2]

void sp::gplot::plot_add_mat ( const arma::mat &  y)
inline

Push multiple plot, each row gives a plot without label.

Parameters
yy matrix
Examples:
adaptive_filter.cpp.

Definition at line 354 of file gplot.h.

References sp::gplot::plot_data_s::label, sp::gplot::plot_data_s::linespec, and plot_str2().

Referenced by main().

Here is the call graph for this function:

◆ plot_add_mat() [2/2]

void sp::gplot::plot_add_mat ( const arma::mat &  y,
const std::string  p_lb 
)
inline

Push multiple plot, each row gives a plot with prefix label.

Parameters
yy matrix
p_lbLabel prefix

Definition at line 374 of file gplot.h.

References sp::gplot::plot_data_s::label, sp::gplot::plot_data_s::linespec, and plot_str2().

Here is the call graph for this function:

◆ plot_clear()

void sp::gplot::plot_clear ( void  )
inline

Clear plots.

Definition at line 415 of file gplot.h.

◆ plot_show()

void sp::gplot::plot_show ( void  )
inline

Show plots.

Examples:
adaptive_filter.cpp, filter_plot.cpp, kalman_linear.cpp, kalman_UKF.cpp, and latex.cpp.

Definition at line 395 of file gplot.h.

References plot_ix, and send2gp().

Referenced by main().

Here is the call graph for this function:

◆ plot_str2()

template<typename T1 , typename T2 >
void sp::gplot::plot_str2 ( const T1 &  x,
const T2 &  y 
)
inlineprivate

Plot y vs. x.

Parameters
xx vector
yy vector

Definition at line 45 of file gplot.h.

References send2gp().

Referenced by plot_add(), and plot_add_mat().

Here is the call graph for this function:

◆ reset_term()

void sp::gplot::reset_term ( void  )
inline

Reset output terminal.

Definition at line 754 of file gplot.h.

References send2gp().

Here is the call graph for this function:

◆ send2gp()

void sp::gplot::send2gp ( const char *  cmdstr)
inline

◆ set_blackbody_palette()

void sp::gplot::set_blackbody_palette ( void  )
inline

Set palette to 'black body'.

Definition at line 664 of file gplot.h.

References send2gp().

Here is the call graph for this function:

◆ set_coolwarm_palette()

void sp::gplot::set_coolwarm_palette ( void  )
inline

Set palette to 'cool-warm'.

Definition at line 646 of file gplot.h.

References send2gp().

Here is the call graph for this function:

◆ set_jet_line()

void sp::gplot::set_jet_line ( void  )
inline

Set linetype to Matlab 'jet' NB! doesn't work with X11 -terminal Data from https://github.com/Gnuplotting/gnuplot-palettes.

Definition at line 566 of file gplot.h.

References send2gp().

Here is the call graph for this function:

◆ set_jet_palette()

void sp::gplot::set_jet_palette ( void  )
inline

Set palette to Matlab 'jet' Data from https://github.com/Gnuplotting/gnuplot-palettes.

Definition at line 608 of file gplot.h.

References send2gp().

Here is the call graph for this function:

◆ set_output()

void sp::gplot::set_output ( const char *  name)
inline

Save plot to file.

Parameters
namefilename

Extensions that are supported:

  • png
  • ps
  • eps
  • tex
  • pdf
  • svg
  • emf
  • gif
Note
When 'latex' output is used the '\' must be escaped by '\\' e.g set_xlabel("Frequency $\\\\omega = 2 \\\\pi f$")
Examples:
latex.cpp.

Definition at line 695 of file gplot.h.

References send2gp(), and term.

Referenced by main().

Here is the call graph for this function:

◆ set_parula_line()

void sp::gplot::set_parula_line ( void  )
inline

Set linetype to Matlab 'parula' NB! doesn't work with X11 -terminal Data from https://github.com/Gnuplotting/gnuplot-palettes.

Definition at line 551 of file gplot.h.

References send2gp().

Here is the call graph for this function:

◆ set_parula_palette()

void sp::gplot::set_parula_palette ( void  )
inline

Set palette to Matlab 'parula' Data from https://github.com/Gnuplotting/gnuplot-palettes.

Definition at line 627 of file gplot.h.

References send2gp().

Here is the call graph for this function:

◆ set_set1_line()

void sp::gplot::set_set1_line ( void  )
inline

Set linetype to Matlab 'parula' NB! doesn't work with X11 -terminal Data from https://github.com/Gnuplotting/gnuplot-palettes.

Definition at line 580 of file gplot.h.

References send2gp().

Here is the call graph for this function:

◆ set_term()

void sp::gplot::set_term ( const char *  ttype)
inline

Set output terminal.

Examples:
adaptive_filter.cpp, filter_plot.cpp, image.cpp, kalman_linear.cpp, and kalman_UKF.cpp.

Definition at line 759 of file gplot.h.

References send2gp().

Referenced by main().

Here is the call graph for this function:

◆ surf()

template<typename T >
void sp::gplot::surf ( const arma::Mat< T > &  x)
inline

Plot mat as surf.

Parameters
xx matrix

Definition at line 541 of file gplot.h.

References mesh(), and send2gp().

Here is the call graph for this function:

◆ title()

void sp::gplot::title ( const char *  name)
inline

Set windowtitle.

Parameters
nametitle string

Definition at line 274 of file gplot.h.

References send2gp().

Here is the call graph for this function:

◆ window() [1/2]

void sp::gplot::window ( const int  fig,
const char *  name,
const int  x,
const int  y,
const int  width,
const int  height 
)
inline

Configure the figure used Windows environment.

Parameters
figFigure number
nameWindow name
xx position of upper left corner
yy position of upper left corner
widthwidth of window
heightheight of window
Examples:
adaptive_filter.cpp, filter_plot.cpp, image.cpp, kalman_linear.cpp, kalman_UKF.cpp, and spectrum.cpp.

Definition at line 182 of file gplot.h.

References send2gp().

Referenced by main(), and window().

Here is the call graph for this function:

◆ window() [2/2]

void sp::gplot::window ( const char *  name,
const int  x,
const int  y,
const int  width,
const int  height 
)
inline

Configure the figure/window - used in Linux environment where no figure numbers are needed.

Parameters
nameWindow name
xx position of upper left corner
yy position of upper left corner
widthwidth of window
heightheight of window

Definition at line 204 of file gplot.h.

References window().

Here is the call graph for this function:

◆ xlabel()

void sp::gplot::xlabel ( const char *  label)
inline

Set label for X-axis.

Parameters
labellabel string
Examples:
filter_plot.cpp.

Definition at line 236 of file gplot.h.

References send2gp().

Referenced by main().

Here is the call graph for this function:

◆ xlim()

void sp::gplot::xlim ( const double  xmin,
const double  xmax 
)
inline

Set X-axis range.

Parameters
xminxmin
xmaxxmax
Examples:
latex.cpp.

Definition at line 287 of file gplot.h.

References send2gp().

Referenced by image(), and main().

Here is the call graph for this function:

◆ ylabel()

void sp::gplot::ylabel ( const char *  label)
inline

Set label for X-axis.

Parameters
labellabel string
Examples:
filter_plot.cpp.

Definition at line 248 of file gplot.h.

References send2gp().

Referenced by main().

Here is the call graph for this function:

◆ ylim()

void sp::gplot::ylim ( const double  ymin,
const double  ymax 
)
inline

Set Y-axis range.

Parameters
yminymin
ymaxymax

Definition at line 300 of file gplot.h.

References send2gp().

Referenced by image().

Here is the call graph for this function:

Member Data Documentation

◆ fig_ix

int sp::gplot::fig_ix
private

Definition at line 30 of file gplot.h.

◆ gnucmd

FILE* sp::gplot::gnucmd
private

File handle to pipe.

Definition at line 28 of file gplot.h.

Referenced by send2gp().

◆ plot_ix

int sp::gplot::plot_ix
private

Definition at line 31 of file gplot.h.

Referenced by plot_show().

◆ plotlist

std::vector<plot_data_s> sp::gplot::plotlist
private

Definition at line 38 of file gplot.h.

◆ term

std::string sp::gplot::term
private

Definition at line 29 of file gplot.h.

Referenced by set_output().


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