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
Collaboration diagram for Usage of JKQTBasePlotter Non-Visible Class:

It is also possible to use it in a standalone fashion to generate plots without generating a window. Note that the baseplotter class still requires the widgets+gui modules of Qt, because it contains code to e.g. display pint or export preview dialogs!

Here is an example of how to do this (it is taken from the command-line tool Tool (JKQTMathText): Command-Line Utility jkqtplotter_doc_imagegenerator):

First we generate the JKQTBasePlotter object and add some data to the internal JKQTPDatastore

JKQTBasePlotter plot(true);
JKQTPDatastore* ds=plot.getDatastore();
size_t cx=ds->addCopiedColumn(QVector<double>{-1.5,-0.5,0.5,1.5,2.5},"x");
size_t cy=ds->addCopiedColumn(QVector<double>{-0.75,-0.3,-0.05,0.2,0.65},"y");
base class for 2D plotter classes (used by the plotter widget JKQTPlotter)
Definition jkqtpbaseplotter.h:394
This class manages data columns (with entries of type double ), used by JKQTPlotter/JKQTBasePlotter t...
Definition jkqtpdatastorage.h:282
size_t addCopiedColumn(TIterator first, TIterator last, const QString &name=QString(""))
add one column to the datastore. It will be filled with the values from first ... last
Definition jkqtpdatastorage.h:871

Now we set the range of x/y plot coordinates ...

plot.setXY(-0.8,2.2,-0.5,0.7);

and the size of the widget, i.e. the size of the plot in the windowing system.

plot.setWidgetSize(150,50);

Now we can add graphs to the plotter, e.g.

g->setXColumn(cx);
g->setYColumn(cy);
plot.addGraph(g);
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 line plots. This also alows to draw symbols at the data points.
Definition jkqtplines.h:61

Finally we store an image of the plot as PNG-file:

plot.saveAsPixelImage("output.png", false, "png");

Alternatively you can obtain a QImage of the plot using JKQTBasePlotter::grabPixelImage() or copy the image to the clipboard using JKQTBasePlotter::copyPixelImage(). Also storages as PDF and SVG is available via JKQTBasePlotter::saveAsPDF() and JKQTBasePlotter::saveAsSVG().

With simlar code you can also integrate JKQTBasePlotter into your own widgets.

This class is immpleented in a such a way that different instances can be used in different parallel threads, i.e. the class is re-entrant. There are however access to different cached data is synchronized between all threads (i.e. static internal caches are used), which limmits the acheavable parallelization speedup!

See Example (JKQTPlotter): Multi-Threaded (Parallel) Plotting for an example of multi-threaded plotting!