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
|
This project (see ./examples/contourplot/
) shows how to draw contour plots with JKQTPlotter.
The source code of the main application is (see contourplot.cpp
).
First the electric potential from a quadrupole is calculated and stored in an image column inside the JKQTPDatastore:
Then this image column can be drawn with a JKQTPColumnContourPlot
:
Note that we created the list of contour levels to draw explicitly here using JKQTPColumnContourPlot::addContourLevel()
. There are also methods JKQTPColumnContourPlot::createContourLevels()
and JKQTPColumnContourPlot::createContourLevelsLog()
to auto-generate these from the data-range with linear or logarithmic spacing, but both options do not yield good results here. The code above generates these contour levels:
The result looks like this:
You can change the way that the colors for the contours are chosen by calling JKQTPColumnContourPlot::setContourColoringMode()
with another mode:
JKQTPColumnContourPlot::SingleColorContours
uses the same color (set by JKQTPColumnContourPlot::setLineColor()
) for all contours.JKQTPColumnContourPlot::ColorContoursFromPaletteByValue
is the mode used for the example above, which chooses the color from the current color-palette based on the current image data range and the actual level of the contour line. JKQTPColumnContourPlot::ColorContoursFromPalette
chooses the color by evenly spacing the contour lines over the full color palette. the line-color will then have no connection to the actual value of the level.In all modes you can override the coloring of single levels by calling JKQTPColumnContourPlot::setOverrideColor(level, color)
. In the example above this looks like this:
This code results (in the default coloring mode JKQTPColumnContourPlot::ColorContoursFromPaletteByValue
) in:
In order to demonstrate the caching implemented in the contour plot, there is optional animation code inside this example, in the form of the class ContourPlotAnimator
(see (see ContourPlotAnimator.cpp
).
The code therein results in an animation like this:
Note that zooming can still be perfomred without the need to recalculate the contour lines.