SigPack - the C++ signal processing library
 
Loading...
Searching...
No Matches
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_UKF.cpp, kalman_linear.cpp, latex.cpp, and spectrum.cpp.

Definition at line 26 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 104 of file gplot.h.

References err_handler, fig_ix, gnucmd, plot_ix, plotlist, and term.

◆ ~gplot()

sp::gplot::~gplot ( )
inline

Destructor.

Definition at line 130 of file gplot.h.

References gnucmd.

Member Function Documentation

◆ close_window()

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

Close window.

Definition at line 217 of file gplot.h.

References send2gp(), and term.

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 162 of file gplot.h.

References gnucmd.

◆ fast_plot() [1/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(), gnucmd, 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 std::string  fmt_args = "with lines" 
)
inline

Plot vector, fast version.

Parameters
xx vector

Definition at line 429 of file gplot.h.

References flush_cmd_buf(), get_type(), gnucmd, 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 171 of file gplot.h.

References fig_ix, send2gp(), and term.

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 154 of file gplot.h.

References gnucmd.

Referenced by fast_plot(), fast_plot(), image(), 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 68 of file gplot.h.

References err_handler.

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

◆ grid_off()

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

Set grid.

Definition at line 237 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 229 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::Cube< T > &  x)
inline

Plot cube as image.

Parameters
xx matrix (R,G,B)

Definition at line 489 of file gplot.h.

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

Here is the call graph for this function:

◆ image() [2/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 471 of file gplot.h.

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

Referenced by main(), and main().

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 272 of file gplot.h.

References label(), and send2gp().

Referenced by label(), main(), xlabel(), and ylabel().

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 520 of file gplot.h.

References flush_cmd_buf(), get_type(), gnucmd, 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_UKF.cpp, kalman_linear.cpp, and latex.cpp.

Definition at line 325 of file gplot.h.

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

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 343 of file gplot.h.

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

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 360 of file gplot.h.

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

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 380 of file gplot.h.

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

Here is the call graph for this function:

◆ plot_clear()

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

Clear plots.

Definition at line 419 of file gplot.h.

References plot_ix, and plotlist.

◆ plot_show()

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

Show plots.

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

Definition at line 401 of file gplot.h.

References plot_ix, plotlist, 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 47 of file gplot.h.

References plot_ix, and send2gp().

Referenced by plot_add(), plot_add(), plot_add_mat(), 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 749 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 659 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 641 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 560 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 603 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 690 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 545 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 622 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 575 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_UKF.cpp, and kalman_linear.cpp.

Definition at line 757 of file gplot.h.

References send2gp(), and term.

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 535 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 284 of file gplot.h.

References send2gp().

Here is the call graph for this function:

◆ window() [1/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 209 of file gplot.h.

References window().

Here is the call graph for this function:

◆ window() [2/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_UKF.cpp, kalman_linear.cpp, and spectrum.cpp.

Definition at line 190 of file gplot.h.

References fig_ix, send2gp(), and term.

Referenced by main(), main(), and 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 246 of file gplot.h.

References label(), and 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 297 of file gplot.h.

References send2gp().

Referenced by image(), 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 258 of file gplot.h.

References label(), and 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 310 of file gplot.h.

References send2gp().

Referenced by image(), and image().

Here is the call graph for this function:

Member Data Documentation

◆ fig_ix

int sp::gplot::fig_ix
private

Definition at line 31 of file gplot.h.

Referenced by figure(), gplot(), and window().

◆ gnucmd

FILE* sp::gplot::gnucmd
private

File handle to pipe.

Definition at line 29 of file gplot.h.

Referenced by draw_now(), fast_plot(), fast_plot(), flush_cmd_buf(), gplot(), image(), image(), mesh(), send2gp(), and ~gplot().

◆ plot_ix

int sp::gplot::plot_ix
private

◆ plotlist

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

Definition at line 40 of file gplot.h.

Referenced by gplot(), plot_add(), plot_add(), plot_add_mat(), plot_add_mat(), plot_clear(), and plot_show().

◆ term

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

Definition at line 30 of file gplot.h.

Referenced by close_window(), figure(), gplot(), set_output(), set_term(), and window().


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