1. How to use a PPlot?
    1. A simple plot
    2. Two plot items with legend data
    3. Plot region (setting margins)
    4. Axis setup
    5. Title and background color
    6. Grid
    7. Indexed plot data
    8. Data with strings

How to use a PPlot?


In the code snippets below it is assumed that you have declared a variable of the main class (PPlot)
PPlot mPPlot;

A simple plot

You make a plot by supplying datasets for x and y. A datataset (PlotData) is an stl container of floats.
// make x/y datasets for one plotitem
PlotData *xdata = new PlotData ();

PlotData *ydata = new PlotData ();
// fill them as any stl container (with floats)
for (...) {
   xdata->push_back (...);
   ydata->push_back(...);
}  
// add item to the plot
mPPlot.mPlotDataContainer.AddXYPlot (xdata, ydata);// takes ownership

Two plot items with legend data

You can have multiple plotitems in one plot. You simply make and fill datasets and legend info as follows
PlotData *xdata1 = ...;// see above how to make two x/y datasets
PlotData *ydata1 = ...;
PlotData *xdata2 = ...;
PlotData *ydata2 = ...;
LegendData *legend1 = new LegendData ();// let us setup the first legend
legend1->mName = "foo";
legend1->mColor = PColor (100,200,200);// just an rgb value
LegendData *legend2 = ...;// do something similar for the second legend
// add the plotitems
mPPlot.mPlotDataContainer.AddXYPlot (xdata1,ydata1, legend1);
mPPlot.mPlotDataContainer.AddXYPlot (xdata2,ydata2, legend2);

Plot region (setting margins)

A plot consists of a plot region surrounded by margins. In the picture below, the plot region is the dark gray area. As you can see some things are drawn outside the plot area. If you would put all margins to zero you would only see the plot area and the title and y-axis ticks would fall outside the widget.
plot region

Margins can be set manually with
mPPlot.mMargins.mLeft = 20;
mPPlot.mMargins.mRight = 20;
mPPlot.mMargins.mTop = 20;
mPPlot.mMargins.mBottom = 20;

Axis setup

You can influence the way the axes are drawn through the two axis setup members
mPPlot.mXAxisSetup;
mPPlot.mYAxisSetyp;
You can turn of autoscaling and provide a customized range for an axis (for instance the x axis) like this
mPPlot.mXAxisSetup.SetAutoScale (false);
mPPlot.mXAxisSetup.mMin = -5;
mPPlot.mXAxisSetup.mMax = 3;
You can use autoscale to the maximum of your data but keep the minimum at a fixed value like this
mPPlot.mXAxisSetup.mAutoScaleMin = false;// do not change the minumum
mPPlot.mXAxisSetup.mMin = 0;
mPPlot.mXAxisSetup.mAutoScaleMax = true;// do change the maximum according to data
Logarithmic scale is achieved with
mPPlot.mXAxisSetup.mLogScale = true;
mPPlot.mXAxisSetup.mLogBase = 10;// 10 is the default
By default an axis goes through the origin. As a result it may become invisible. You can prevent this with
mPPlot.mXAxisSetup.mCrossOrigin = false;// this way the axis will always be visible
You can give the axis a label with
mPPlot.mXAxisSetup.mLabel = "bar";
To change the direction in which the data run with respect to screen coordinates you can specify
mPPlot.mXAxisSetup.mAscending=true;// default: left is minimum, right is maximum
mPPlot.mYAxisSetup.mAscending=false;// default : bottom is minimum, top is maximum

Title and background color

You can give the plot a title and a background color with
mPPlot.mPlotBackground.mTitle = "nice curves";
mPPlot.mPlotBackground.mTransparent = false;
mPPlot.mPlotBackground.mPlotRegionBackColor = PColor (3,100,130);

Grid

A grid is drawn when you state
mPPlot.mGridInfo.mXGridOn = true;
mPPlot.mGridInfo.mYGridOn = true;

Indexed plot data

Quite often you don't care about xdata: they shoul just be increasing numbers. You can create such a set with
 PlotData *theYData  = ...
// fill ydata here
DummyData *theXData = new DummyData (theYData->size ());// make the indexed data
mPPlot.mPlotDataContainer.AddXYPlot (theXData, theYData);
An even more simple solution is to supply a null value as xdata
mPPlot.mPlotDataContainer.AddXYPlot (0, theYData);

Data with strings

Sometimes your data can take on some discrete values that are conveniently described with strings (for instance weekdays and months). You can make such a dataset like this
StringData *theStringData = new StringData ();
for () {
    theStringData->AddItem ("string i here");
}
the end.
SourceForge Logo