mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-11-15 10:05:47 +08:00
added simple example for JKQTPxyParametrizedScatterGraph
This commit is contained in:
parent
4099cfcd7e
commit
f4ce4c875b
@ -50,6 +50,7 @@ addSimpleTest(filledgraphs)
|
||||
addSimpleTest(speed)
|
||||
addSimpleTest(rgbimageplot_qt)
|
||||
addSimpleTest(impulsesplot)
|
||||
addSimpleTest(paramscatterplot)
|
||||
#addSimpleTest(imageplot_nodatastore)
|
||||
#addSimpleTest(rgbimageplot_opencv)
|
||||
#addSimpleTest(imageplot_opencv)
|
||||
|
@ -27,6 +27,7 @@ All test-projects are Qt-projects that use qmake to build. You can load them int
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/JKQTPbarVerticalGraphStacked_small.png)<br>![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/JKQTPbarHorizontalGraphStacked_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/simpletest_stackedbars) | [Stacked Bar Charts](https://github.com/jkriege2/JKQtPlotter/tree/master/test/simpletest_stackedbars) | `JKQTPbarVerticalStackableGraph`, `JKQTPbarHorizontalStackableGraph`<br/>C++-style vectors of data |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_filledgraphs_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/simpletest_filledgraphs) | [Filled Curve Plots](https://github.com/jkriege2/JKQtPlotter/tree/master/test/simpletest_filledgraphs) | `JKQTPbarVerticalGraph`<br/>setting/altering data in `JKQTPdatstore` directly<br/> transparent plots<br/>calculating histograms |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_impulsesplot_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/simpletest_impulsesplot) | [Impulse Plots](https://github.com/jkriege2/JKQtPlotter/tree/master/test/simpletest_impulsesplot) | `JKQTPimpulsesVerticalGraph` and `JKQTPimpulsesHorizontalGraph`<br/>C++-style QVector as plot data |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_paramscatterplot_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/simpletest_paramscatterplot) | [Scatter Graph with Parametrized Symbols/Colors](https://github.com/jkriege2/JKQtPlotter/tree/master/test/simpletest_paramscatterplot) | `JKQTPimpulsesVerticalGraph` and `JKQTPimpulsesHorizontalGraph`<br/>C++-style QVector as plot data |
|
||||
|
||||
### Styling the Plot, Keys, Axes, ...
|
||||
|
||||
|
BIN
screenshots/jkqtplotter_simpletest_paramscatterplot.png
Normal file
BIN
screenshots/jkqtplotter_simpletest_paramscatterplot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 74 KiB |
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
BIN
screenshots/jkqtplotter_simpletest_paramscatterplot_small.png
Normal file
BIN
screenshots/jkqtplotter_simpletest_paramscatterplot_small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
117
test/simpletest_paramscatterplot/README.md
Normal file
117
test/simpletest_paramscatterplot/README.md
Normal file
@ -0,0 +1,117 @@
|
||||
[Back to JKQTPlotter main page](https://github.com/jkriege2/JKQtPlotter/)
|
||||
|
||||
# JKQtPlotter
|
||||
|
||||
## Scatter Graph with Parametrized Symbols/Colors
|
||||
This project (see `./test/simpletest_paramscatterplot/`) demonstrates the capabilities of `JKQTPxyParametrizedScatterGraph`. This graph class plots symbol&line-graphs, juts like [`JKQTPxyLineGraph`](https://github.com/jkriege2/JKQtPlotter/blob/master/test/simpletest_symbols_and_styles/) and in addition modifies several properties of each plot point by data from an additional column. These properties can be modified:
|
||||
- symbol size
|
||||
- symbol type
|
||||
- symbol/line color
|
||||
- line width
|
||||
|
||||
The source code of the main application can be found in [`jkqtplotter_simpletest_paramscatterplot.cpp`](https://github.com/jkriege2/JKQtPlotter/blob/master/test/simpletest_paramscatterplot/jkqtplotter_simpletest_paramscatterplot.cpp). First, several datasets are generated and added to the internal datastore. the resulting datatable looks like this:
|
||||
|
||||
![jkqtplotter_simpletest_paramscatterplot](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_paramscatterplot_datatable.png)
|
||||
|
||||
Then several plots are added that modify different properties.
|
||||
|
||||
The simplest case is to modify the symbol type. Simply set the property `symbolColumn` with `graph1->set_symbolColumn(columnP)` to a data column. The values in the data column will be cast to an integer and then will be translated to `JKQTPgraphSymbols`. If the numbers are larger than the available symbol types in `JKQTPgraphSymbols`, the graph will cycle through the available symbols (via a modulo-operation with the max. symbol count!).
|
||||
```c++
|
||||
JKQTPxyParametrizedScatterGraph* graph1=new JKQTPxyParametrizedScatterGraph(&plot);
|
||||
graph1->set_xColumn(columnX);
|
||||
graph1->set_yColumn(columnY1);
|
||||
graph1->set_symbolColumn(columnP);
|
||||
graph1->set_drawLine(true);
|
||||
graph1->set_color(QColor("blueviolet"));
|
||||
graph1->set_title("1: symbol type");
|
||||
plot.addGraph(graph1);
|
||||
```
|
||||
|
||||
|
||||
The next two code snippets show how to modify the size of the symbols and the line width of the lines, connecting the symbols (ensure to set `graph6->set_drawLine(true)`, because otherwise no line will be drawn). The principle is the same as above, but here you need to set the properties `sizeColumn` for the symbol size and `linewidthColumn` for the line width. All values in the line width or symbol size columns are interpreted as sizes in dtp points (pt)!
|
||||
```c++
|
||||
// symbol size
|
||||
JKQTPxyParametrizedScatterGraph* graph3=new JKQTPxyParametrizedScatterGraph(&plot);
|
||||
graph3->set_xColumn(columnX);
|
||||
graph3->set_yColumn(columnY3);
|
||||
graph3->set_sizeColumn(columnS);
|
||||
graph3->set_symbol(JKQTPfilledCircle);
|
||||
graph3->set_drawLine(true);
|
||||
graph3->set_title("3: symbol size");
|
||||
plot.addGraph(graph3);
|
||||
|
||||
// line width
|
||||
JKQTPxyParametrizedScatterGraph* graph6=new JKQTPxyParametrizedScatterGraph(&plot);
|
||||
graph6->set_xColumn(columnX);
|
||||
graph6->set_yColumn(columnY6);
|
||||
graph6->set_linewidthColumn(columnLW);
|
||||
graph6->set_drawLine(true);
|
||||
graph6->set_symbol(JKQTPnoSymbol);
|
||||
graph6->set_title("6: line width");
|
||||
plot.addGraph(graph6);
|
||||
```
|
||||
|
||||
|
||||
Finally you can set the color of each symbol, based on data in the column `colorColumn`. Here two possibilities exist: First you can store the RGB(A) value for each datapoint explicitly. For this, you first need to create the data in the column, using the Qt-function [`qRgb()`](http://doc.qt.io/qt-5/qcolor.html#qRgb) or [`qRgba()`}(http://doc.qt.io/qt-5/qcolor.html#qRgba):
|
||||
```c++
|
||||
QVector<double> RGB;
|
||||
const int Ndata=10; // number of plot points in each curve
|
||||
for (int i=0; i<Ndata; i++) {
|
||||
const double x=double(i)/double(Ndata)*2.0*M_PI;
|
||||
RGB<<double(qRgb(double(i)/double(Ndata)*255,0,255-double(i)/double(Ndata)*255));
|
||||
}
|
||||
size_t columnRGB=ds->addCopiedColumn(RGB, "rgb");
|
||||
```c++
|
||||
Basically the data points in a RGB(A)-column will be interpreted by castig them to [`QRgb`](http://doc.qt.io/qt-5/qcolor.html#QRgb-typedef).
|
||||
|
||||
Now you can add the graph. In order to interpret the color column as RGB(A)-values, ensure to set `graph4->set_colorColumnContainsRGB(true)`:
|
||||
```c++
|
||||
JKQTPxyParametrizedScatterGraph* graph4=new JKQTPxyParametrizedScatterGraph(&plot);
|
||||
graph4->set_xColumn(columnX);
|
||||
graph4->set_yColumn(columnY4);
|
||||
graph4->set_colorColumn(columnRGB);
|
||||
graph4->set_colorColumnContainsRGB(true);
|
||||
graph4->set_drawLine(true);
|
||||
graph4->set_symbol(JKQTPfilledDownTriangle);
|
||||
graph4->set_title("4: RGB-color");
|
||||
plot.addGraph(graph4);
|
||||
```
|
||||
|
||||
The second variant for setting the color of each datapoint is by mapping the values in the column to a color palette (`JKQTPMathImageRYGB` in this example). For this you simply need to define the color coumn and the palette to use. By default, the color palette spans the full range of values in `colorColumn`:
|
||||
```c++
|
||||
JKQTPxyParametrizedScatterGraph* graph2=new JKQTPxyParametrizedScatterGraph(&plot);
|
||||
graph2->set_xColumn(columnX);
|
||||
graph2->set_yColumn(columnY2);
|
||||
graph2->set_colorColumn(columnC);
|
||||
graph2->set_palette(JKQTPMathImageRYGB);
|
||||
graph2->set_symbol(JKQTPfilledRect);
|
||||
graph2->set_drawLine(true);
|
||||
graph2->set_title("2: color");
|
||||
graph2->get_colorBarRightAxis()->set_axisLabel("color scale for graph2");
|
||||
plot.addGraph(graph2);
|
||||
```
|
||||
Note: If you want to set the range manually, use `ste_imageMin()` and `set_imageMax()` after setting `set_autoImageRange(false)`.
|
||||
|
||||
|
||||
Note also that it is possible to combine any of parametrizations above in a single graph, by setting two or more columns:
|
||||
```c++
|
||||
JKQTPxyParametrizedScatterGraph* graph5=new JKQTPxyParametrizedScatterGraph(&plot);
|
||||
graph5->set_xColumn(columnX);
|
||||
graph5->set_yColumn(columnY5);
|
||||
graph5->set_colorColumn(columnC);
|
||||
graph5->set_sizeColumn(columnS);
|
||||
graph5->set_palette(JKQTPMathImageBLUEYELLOW);
|
||||
graph5->set_drawLine(true);
|
||||
graph5->set_title("5: color+size");
|
||||
graph5->get_colorBarRightAxis()->set_axisLabel("color scale for graph5");
|
||||
plot.addGraph(graph5);
|
||||
```
|
||||
|
||||
|
||||
The full test appication combines all these variants and the result looks like this:
|
||||
|
||||
![jkqtplotter_simpletest_paramscatterplot](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_paramscatterplot.png)
|
||||
|
||||
|
||||
|
||||
[Back to JKQTPlotter main page](https://github.com/jkriege2/JKQtPlotter/)
|
@ -0,0 +1,158 @@
|
||||
#include <QApplication>
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
#include "jkqtplotter/jkqtpelements.h"
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
// 1. create a plotter window and get a pointer to the internal datastore (for convenience)
|
||||
JKQtPlotter plot;
|
||||
JKQTPdatastore* ds=plot.getDatastore();
|
||||
|
||||
// 2. now we create a vector of x- and y-values for a simple plot (a sine curve)
|
||||
// in addition, a vector P will hold values that will be mapped onto different plot styles
|
||||
// and a vector C that will be mapped onto different colors
|
||||
QVector<double> X, Y1, Y2, Y3, Y4, Y5, Y6, Y7, P, C, S, RGB, LW;
|
||||
const int Ndata=10; // number of plot points in each curve
|
||||
for (int i=0; i<Ndata; i++) {
|
||||
const double x=double(i)/double(Ndata)*2.0*M_PI;
|
||||
X<<x;
|
||||
Y1<<1.5+sin(x);
|
||||
Y2<<3.5+sin(x);
|
||||
Y3<<5.5+sin(x);
|
||||
Y4<<7.5+sin(x);
|
||||
Y5<<9.5+sin(x);
|
||||
Y6<<11.5+sin(x);
|
||||
Y7<<12.5+sin(x);
|
||||
P<<(i+2);
|
||||
C<<x;
|
||||
S<<5*(i+1);
|
||||
LW<<(i+1)*1.5;
|
||||
RGB<<double(qRgb(double(i)/double(Ndata)*255,0,255-double(i)/double(Ndata)*255));
|
||||
}
|
||||
// and copy it to the datastore
|
||||
size_t columnX=ds->addCopiedColumn(X, "x");
|
||||
size_t columnY1=ds->addCopiedColumn(Y1, "y1");
|
||||
size_t columnY2=ds->addCopiedColumn(Y2, "y2");
|
||||
size_t columnY3=ds->addCopiedColumn(Y3, "y3");
|
||||
size_t columnY4=ds->addCopiedColumn(Y4, "y4");
|
||||
size_t columnY5=ds->addCopiedColumn(Y5, "y5");
|
||||
size_t columnY6=ds->addCopiedColumn(Y6, "y6");
|
||||
size_t columnY7=ds->addCopiedColumn(Y7, "y7");
|
||||
size_t columnP=ds->addCopiedColumn(P, "point_style");
|
||||
size_t columnC=ds->addCopiedColumn(C, "color_value");
|
||||
size_t columnS=ds->addCopiedColumn(S, "size");
|
||||
size_t columnLW=ds->addCopiedColumn(LW, "linewidth");
|
||||
size_t columnRGB=ds->addCopiedColumn(RGB, "rgb");
|
||||
|
||||
|
||||
// 3. now we make several graphs. In each one, another property of the graph is controlled by
|
||||
// a datacolumn
|
||||
|
||||
// 3.1 for graph1, we use dataset X/Y1
|
||||
// and the symbol type is choose according to the contents of column P:
|
||||
JKQTPxyParametrizedScatterGraph* graph1=new JKQTPxyParametrizedScatterGraph(&plot);
|
||||
graph1->set_xColumn(columnX);
|
||||
graph1->set_yColumn(columnY1);
|
||||
graph1->set_symbolColumn(columnP);
|
||||
graph1->set_drawLine(true);
|
||||
graph1->set_color(QColor("blueviolet"));
|
||||
graph1->set_title("1: symbol type");
|
||||
plot.addGraph(graph1);
|
||||
|
||||
// 3.2 for graph2, we use dataset X/Y2
|
||||
// and the symbol color is choose according to the contents of column C
|
||||
// and the actual colors are chose from palette JKQTPMathImageRYGB:
|
||||
JKQTPxyParametrizedScatterGraph* graph2=new JKQTPxyParametrizedScatterGraph(&plot);
|
||||
graph2->set_xColumn(columnX);
|
||||
graph2->set_yColumn(columnY2);
|
||||
graph2->set_colorColumn(columnC);
|
||||
graph2->set_palette(JKQTPMathImageRYGB);
|
||||
graph2->set_symbol(JKQTPfilledRect);
|
||||
graph2->set_drawLine(true);
|
||||
graph2->set_title("2: color");
|
||||
graph2->get_colorBarRightAxis()->set_axisLabel("color scale for graph2");
|
||||
plot.addGraph(graph2);
|
||||
|
||||
// 3.3 for graph3, we use dataset X/Y3
|
||||
// and the symbol size is choose according to the contents of column S:
|
||||
JKQTPxyParametrizedScatterGraph* graph3=new JKQTPxyParametrizedScatterGraph(&plot);
|
||||
graph3->set_xColumn(columnX);
|
||||
graph3->set_yColumn(columnY3);
|
||||
graph3->set_sizeColumn(columnS);
|
||||
graph3->set_symbol(JKQTPfilledCircle);
|
||||
graph3->set_drawLine(true);
|
||||
graph3->set_title("3: symbol size");
|
||||
plot.addGraph(graph3);
|
||||
|
||||
// 3.4 for graph4, we use X/Y4
|
||||
// and the symbol color is choose according to the contents of column RGB,
|
||||
// which directly contains the RGB values, as set with qRgb():
|
||||
JKQTPxyParametrizedScatterGraph* graph4=new JKQTPxyParametrizedScatterGraph(&plot);
|
||||
graph4->set_xColumn(columnX);
|
||||
graph4->set_yColumn(columnY4);
|
||||
graph4->set_colorColumn(columnRGB);
|
||||
graph4->set_colorColumnContainsRGB(true);
|
||||
graph4->set_drawLine(true);
|
||||
graph4->set_symbol(JKQTPfilledDownTriangle);
|
||||
graph4->set_title("4: RGB-color");
|
||||
plot.addGraph(graph4);
|
||||
|
||||
// 3.5 for graph2, we use dataset X/Y5
|
||||
// and the symbol color and size are choose according to the contents
|
||||
// of columns C and S respectively.
|
||||
// The actual colors are chose from palette JKQTPMathImageBLUEYELLOW:
|
||||
JKQTPxyParametrizedScatterGraph* graph5=new JKQTPxyParametrizedScatterGraph(&plot);
|
||||
graph5->set_xColumn(columnX);
|
||||
graph5->set_yColumn(columnY5);
|
||||
graph5->set_colorColumn(columnC);
|
||||
graph5->set_sizeColumn(columnS);
|
||||
graph5->set_palette(JKQTPMathImageBLUEYELLOW);
|
||||
graph5->set_drawLine(true);
|
||||
graph5->set_title("5: color+size");
|
||||
graph5->get_colorBarRightAxis()->set_axisLabel("color scale for graph5");
|
||||
plot.addGraph(graph5);
|
||||
|
||||
// 3.6 for graph2, we use dataset X/Y6
|
||||
// and the line width is set by column LW:
|
||||
JKQTPxyParametrizedScatterGraph* graph6=new JKQTPxyParametrizedScatterGraph(&plot);
|
||||
graph6->set_xColumn(columnX);
|
||||
graph6->set_yColumn(columnY6);
|
||||
graph6->set_linewidthColumn(columnLW);
|
||||
graph6->set_drawLine(true);
|
||||
graph6->set_symbol(JKQTPnoSymbol);
|
||||
graph6->set_title("6: line width");
|
||||
plot.addGraph(graph6);
|
||||
|
||||
// 3.7 for graph2, we use dataset X/Y7
|
||||
// and the line width is set by column LW and the color from palette JKQTPMathImageBLUEYELLOW via column C:
|
||||
JKQTPxyParametrizedScatterGraph* graph7=new JKQTPxyParametrizedScatterGraph(&plot);
|
||||
graph7->set_xColumn(columnX);
|
||||
graph7->set_yColumn(columnY7);
|
||||
graph7->set_linewidthColumn(columnLW);
|
||||
graph7->set_drawLine(true);
|
||||
graph7->set_colorColumn(columnC);
|
||||
graph7->set_palette(JKQTPMathImageBLUEYELLOW);
|
||||
graph7->set_symbol(JKQTPnoSymbol);
|
||||
graph7->set_colorBarRightVisible(false);
|
||||
graph7->set_colorBarTopVisible(false);
|
||||
graph7->set_title("7: color+line width");
|
||||
plot.addGraph(graph7);
|
||||
|
||||
// 4. autoscale the plot so the graph is contained and format the coordinate system and key
|
||||
plot.get_plotter()->set_keyPosition(JKQTPkeyOutsideBottomLeft);
|
||||
plot.get_plotter()->set_keyLayout(JKQTPkeyLayoutOneRow);
|
||||
plot.getXAxis()->set_axisLabel("x-axis");
|
||||
plot.getYAxis()->set_axisLabel("y-axis");
|
||||
plot.getXAxis()->set_drawGrid(false);
|
||||
plot.getYAxis()->set_drawGrid(false);
|
||||
plot.zoomToFit();
|
||||
|
||||
// 5. show plotter and make it a decent size
|
||||
plot.show();
|
||||
plot.resize(800,600);
|
||||
|
||||
return app.exec();
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
# source code for this simple demo
|
||||
SOURCES = jkqtplotter_simpletest_paramscatterplot.cpp
|
||||
|
||||
# configure Qt
|
||||
CONFIG += qt
|
||||
QT += core gui xml svg
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
|
||||
|
||||
# output executable name
|
||||
TARGET = jkqtplotter_simpletest_paramscatterplot
|
||||
|
||||
|
||||
# include JKQtPlotter source code
|
||||
DEPENDPATH += . ../../lib
|
||||
INCLUDEPATH += ../../lib
|
||||
CONFIG (debug, debug|release):LIBS += -L../../lib/debug -ljkqtplotterlib
|
||||
CONFIG (release):LIBS += -L../../lib/release -ljkqtplotterlib
|
||||
|
||||
win32-msvc*: DEFINES += _USE_MATH_DEFINES
|
||||
|
||||
# here you can activate some debug options
|
||||
#DEFINES += SHOW_JKQTPLOTTER_DEBUG
|
||||
#DEFINES += JKQTBP_AUTOTIMER
|
@ -0,0 +1,8 @@
|
||||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS += jkqtplotterlib jkqtplotter_simpletest_paramscatterplot
|
||||
|
||||
jkqtplotterlib.file = ../../lib/jkqtplotterlib.pro
|
||||
|
||||
jkqtplotter_simpletest_paramscatterplot.file=$$PWD/jkqtplotter_simpletest_paramscatterplot.pro
|
||||
jkqtplotter_simpletest_paramscatterplot.depends = jkqtplotterlib
|
Loading…
Reference in New Issue
Block a user