JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
Example (JKQTPlotter): Filled Graphs with Error Indicators

This project (see filledgraphs_errors shows how to draw filled graphs with different styles of error indicators.

The source code of the main application is (see filledgraphs_errors.cpp:

// 1. create a plotter window and get a pointer to the internal datastore (for convenience)
// 2. now we create three columns for key and value
size_t columnK=ds->addLinearColumn(9, 0.1*JKQTPSTATISTICS_PI, 1.0*JKQTPSTATISTICS_PI,"k");
size_t columnK2=ds->addLinearColumn(9, 1.1*JKQTPSTATISTICS_PI, 2.0*JKQTPSTATISTICS_PI,"k2");
size_t columnK3=ds->addLinearColumn(9, 2.1*JKQTPSTATISTICS_PI, 3.0*JKQTPSTATISTICS_PI,"k2");
size_t columnV=ds->addColumnCalculatedFromColumn(columnK, [](double x) { return sin(x); }, "v");
size_t columnV2=ds->addColumnCalculatedFromColumn(columnK2, [](double x) { return -sin(x); }, "v2");
size_t columnV3=ds->addColumnCalculatedFromColumn(columnK3, [](double x) { return sin(x); }, "v3");
size_t columnE=ds->addColumnCalculatedFromColumn(columnV, [](double x) { return 0.2*x; }, "error");
size_t columnE2=ds->addColumnCalculatedFromColumn(columnV2, [](double x) { return 0.2*x; }, "error");
size_t columnE3=ds->addColumnCalculatedFromColumn(columnV3, [](double x) { return 0.2*x; }, "error");
// 3. create a graph in the plot, which plots the dataset with symmetric:
graph1->setKeyColumn(columnK);
graph1->setValueColumn(columnV);
graph1->setValueErrorColumn(columnE);
// set error indicator style
graph1->setTitle(QObject::tr("JKQTPErrorBars"));
plot.addGraph(graph1);
// 4. create a second graph in the plot, which plots the second dataset with outer error bars only:
graph2->setKeyColumn(columnK2);
graph2->setValueColumn(columnV2);
graph2->setValueErrorColumn(columnE2);
// set error indicator style
graph2->setTitle(QObject::tr("JKQTPErrorPolygons"));
plot.addGraph(graph2);
// 5. create a third graph in the plot, which plots the second dataset with outer error bars only:
graph3->setKeyColumn(columnK3);
graph3->setValueColumn(columnV3);
graph3->setValueErrorColumn(columnE3);
// set error indicator style
graph3->setTitle(QObject::tr("JKQTPErrorLines"));
plot.addGraph(graph3);
// 6 autoscale the plot so the graph is contained
plot.zoomToFit();
// 7. show plotter and make it a decent size
plot.setWindowTitle(title);
plot.show();
plot.resize(400,400);
void setKeyPosition(const JKQTPKeyPosition &__value)
key position inside or besides the plot area, see JKQTPKeyPositions for details and examples
This class manages data columns (with entries of type double ), used by JKQTPlotter/JKQTBasePlotter t...
Definition jkqtpdatastorage.h:282
size_t addLinearColumn(size_t rows, double start, double end, const QString &name=QString(""))
add a column to the datastore that contains rows rows with monotonely increasing value starting at st...
size_t addColumnCalculatedFromColumn(size_t otherColumn, const std::function< double(double)> &f, const QString &name=QString(""))
Definition jkqtpdatastorage.h:1333
This implements filled curve plots with y errors where the area is filled between the plot line and t...
Definition jkqtpfilledcurve.h:131
void setValueErrorStyle(JKQTPErrorPlotstyle __value)
how to draw the errors (if available) of the x-value
Definition jkqtpfilledcurve.h:164
void setValueErrorColumn(int __value)
the column that contains the error of the x-component of the datapoints
Definition jkqtpfilledcurve.h:172
virtual void setTitle(const QString &__value)
sets the title of the plot (for display in key!).
virtual void setValueColumn(int __value)
sets the column used as "value" for the current graph (typically this call setXColumn(),...
virtual void setKeyColumn(int __value)
sets the column used as "key" for the current graph (typically this call setXColumn(),...
plotter widget for scientific plots (uses JKQTBasePlotter to do the actual drawing)
Definition jkqtplotter.h:364
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
JKQTBasePlotter * getPlotter()
returns the JKQTBasePlotter object internally used for plotting
Definition jkqtplotter.h:404
void addGraph(JKQTPPlotElement *gr)
Definition jkqtplotter.h:784
JKQTPDatastore * getDatastore()
returns a pointer to the datastore used by this object
Definition jkqtplotter.h:611
@ JKQTPErrorLines
a second and third graph line above and below the actual data which indicates the error value
Definition jkqtptools.h:694
@ JKQTPErrorPolygons
line error lines, but with filled range in between
Definition jkqtptools.h:695
@ JKQTPErrorBars
error bars for each data point
Definition jkqtptools.h:711
@ JKQTPKeyInsideBottomLeft
the key is positioned inside on the bottom-left
Definition jkqtptools.h:585
#define JKQTPSTATISTICS_PI
Definition jkqtpmathtools.h:52

The result looks like this:

filledgraphs_errors

In order to draw horizontal error bars, you have to use JKQTPFilledCurveYErrorGraph instead of JKQTPFilledCurveXErrorGraph:

filledgraphs_errors_hor