This project (see ./examples/scatter/
) simply creates a JKQTPlotter widget (as a new window) and adds a single scatter graph of type JKQTPXYScatterGraph (a sine-wave with noise).
The source code of the example can be found in jkqtplotter_scatter.cpp
.
First we create a plotter window and get a pointer to the internal datastore (for convenience):
This class manages data columns (with entries of type double ), used by JKQTPlotter/JKQTBasePlotter t...
Definition jkqtpdatastorage.h:282
plotter widget for scientific plots (uses JKQTBasePlotter to do the actual drawing)
Definition jkqtplotter.h:364
JKQTPDatastore * getDatastore()
returns a pointer to the datastore used by this object
Definition jkqtplotter.h:611
Now we add two columns to the JKQTPDatastore and obtain back-inserter iterators for these:
JKQTPColumnBackInserter backInserter(int i)
returns a back-inserter iterator (JKQTPColumnBackInserter) to the i -th column in the JKQTPDatastore
size_t addColumn(JKQTPColumn col)
add a new column to the datastore and return its ID
Now we create data for a simple plot (a sine curve with random noise):
std::default_random_engine generator;
std::normal_distribution<double> distribution(0,0.5);
const int Ndata=100;
for (int i=0; i<Ndata; i++) {
*colXInserter=x;
*colYInserter=sin(x)+distribution(generator);
colXInserter++;
colYInserter++;
}
Here we create a graph in the plot, which plots the dataset X/Y:
graph1->
setTitle(QObject::tr(
"sine graph"));
virtual void setTitle(const QString &__value)
sets the title of the plot (for display in key!).
void setYColumn(int __value)
the column that contains the y-component of the datapoints
void setXColumn(int __value)
the column that contains the x-component of the datapoints
This implements xy scatter plots. This also alows to draw symbols at the data points.
Definition jkqtpscatter.h:59
Now we add the graph to the plot, so it is actually displayed:
size_t addGraph(JKQTPPlotElement *gr)
Definition jkqtplotter.h:784
Finally we autoscale the plot so the graph is contained:
void zoomToFit(bool zoomX=true, bool zoomY=true, bool includeX0=false, bool includeY0=false, double scaleX=1.05, double scaleY=1.05)
this method zooms the graph so that all plotted datapoints are visible.
Definition jkqtplotter.h:1039
The result looks like this: