2.16 Graphics

Graphics are provided through calls to the gnuplot 1 software. Instances of the class Plot2d and Plot_file are used to generate the data and command files required by the call to gnuplot. A plot can be generated using the set_plot2d function.

Plot2d class

Constructor

Syntax
  Plot2d(void);  
 

Description

Upon initialization, a Plot2d object contain an empty graph. Data, title, label and other goodies can be added using the following member functions:

Return Value

None

addcommand

Syntax
void addcommand(const char * gcom);

Description

This function adds the command specified by the string gcom to the gnuplot command file. Ex: mygraph.addcommand("set grid").

Note: see the gnuplot documentation for the list of commands.

Return Value

None

addcurve

Syntax
void addcurve(const Matrix & data,  
              const char * label = "",  
              int type = LINES);

Description

This function add the curves specified by the n× 2 matrix data to the plot using the string label for the legend and type for the curve line type. Defined line types are:

See the gnuplot documentation for the description of these line types.

Return Value

None

dump

Syntax
void dump(void);

Description

This function dumps the current content of the object to stdout.

Return Value

None

gnuplot

Syntax
void gnuplot(void);

Description

This function calls gnuplot with the current content of the object.

Return Value

None

settitle

Syntax
void settitle(const char * t);

Description

This function sets the title of the graph to the string t.

Return Value

None

setxlabel

Syntax
void setxlabel(const char * t);

Description

This function sets the axis X label of the graph to the string t.

Return Value

None

setylabel

Syntax
void setylabel(const char * t);

Description

This function sets the axis Y label of the graph to the string t.

Return Value

None

Plot_file class

An instance of this class allows the creation of graphics from a data file. This file has to be created with an instance of the class IO_matrix_file.

Constructor

Syntax
Plot_file(const string & filename);

Description

Plot_file object constructor.

Return Value

None

graph

Syntax
short graph(const string & title_graph, const string & label, const short x,  
            const short y, const short x_start, const short y_start,  
            const short y_end);

Description

Create a graphic from a data file (specified by constructor). title_graph and label are used to provide the graphic title and label names in the legend. x refers to the index in the “vector<Matrix> & data” (in class IO_Matrix_file) corresponding to the x axis (ex: time), while y refers to the index in the “vector<Matrix> & data” corresponding to the y axis (ex: joints positions). x_start, y_start and y_end specify which rows of data to use.

Return Value

Status, as a short int.

  1. 0 successful
  2. X_Y_DATA_NO_MATCH
  3. PROBLEM_FILE_READING

set_plot2d

Syntax
void set_plot2d(const char *title_graph, const char *x_axis_title,  
                const char *y_axis_title, const char *label, int type,  
                const Matrix &xdata, const Matrix &ydata,  
                int start_y, int end_y);  
 
void set_plot2d(const char *title_graph, const char *x_axis_title,  
                const char *y_axis_title, const std::vector<char *> label,  
                int type, const Matrix &xdata, const Matrix &ydata,  
                const std::vector<int> & data_select);

Description

This function generates a plot using a range (start_y, end_y) or a selection of columns (data_select) of the ydtata while setting the titles and labels.

Return Value

None