Site Navigation:

Main
Tutorial
Reference
Download
Installation
Screen Shots
Credits

CCPL Tutorial

The simplest way to plot an STL (standard template library) vector is to simply "send it" to a pstream:

      pout << my_data << endp;

my_data may be a vector of any type for which it makes sense to do a static_cast<double>. The endp modifier flushes the stream and advances output to the next page. pout is a previously defined pstream object. For example, an interactive pgplot X Windows stream may be created via:

      pstream pout(pgplot,x11);

Infact simply sending the vector to the pstream is short hand for:

      pout << line_plot(my_data) << endp;

Also supported are point and histogram plots. For example

      pout << point_plot(my_data) << histogram_plot(my_data) << endp;

This plots the vector twice in the one window, first as a set of points and then as a histogram. The objects line_plot, point_plot and histogram_plot are derived from plot_data_squence. This is in turn derived from pstreamable.

Properties of a plot object can be set inline, and cascaded. For example:
      pout << line_plot(data).set_color(green).set_line_style(dashed) << endp;

An important member function of plot_data_sequence is x_values which is used to set the x abscissa. These are set to 0 ... (my_data.size()-1) by default. There are two versions of this function. The first version takes the first x coordinate and a step size:

      pout << line_plot(my_data).x_values( start_x, step_x ) << endp;

The second takes a vector of the x coordinates.

In the examples above, sensible window boundary coordinates are automatically determined. The default x and y limits can be changed using the x_min, x_max, y_min, and y_max stream modifiers:

      pout << x_min(-2.7) << line_plot(data) << endp;

A title, x and y labels, other text, individual lines, and individual points can be plotted by sending the following objects to the pstream.

      title( string mytitle )
      x_lab( string my_xlab )
      y_lab( string my_ylab )
      text( string my_text, double x, double y )
      line( double x1, double y1, double x2, double y2 )
      point( double x, double y )

These objects are all derived from pstreamable, colorable, and possibly other classes, and inherit the associated member functions (such as set_color()).

Bitmap plots of two dimensional boost::multi_array data may be plotted as follows:

      pout << bitmap_plot(my_data) << endp;

In addition to STL vectors and boost multi_array's, TNT and Blitz arrays are supported by including the relevant header file

      #include <pstream.h>
      #include <ccpl_blitz.h>
      
      main() 
      {
        pstream pout(pgplot,x11);
	blitz::Array<int,2> a(3,3) =
	  1, 2, 3,
          3, 2, 1,
	  2, 1, 3;
	pout << bitmap_plot(a) << endp;
      }

CCPL simplifies some common plotting tasks. If you want to do something a little more obscure than CCPL can handle, all you need to do is flush your pstream, do what you want to do using the standard library function calls, then continue using your pstream again.