mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 01:51:49 +08:00
added Example for JKQTPXYScatterGraph and JKQTPXYScatterErrorGraph
This commit is contained in:
parent
b156fc7e40
commit
7839983310
@ -69,6 +69,7 @@ if(JKQtPlotter_BUILD_EXAMPLES)
|
||||
# custom target that generates the images for the JKQTMathText documentation
|
||||
set(JKQTPlotter_GenerateDocScreenshots_DefaultOptions --screenshotdir="${CMAKE_CURRENT_LIST_DIR}/../screenshots/" --screenshot --smallscreenshotplot)
|
||||
set(JKQTPlotter_GenerateDocScreenshots_From
|
||||
scatter
|
||||
)
|
||||
|
||||
add_custom_target(JKQTPlotter_GenerateDocScreenshots
|
||||
|
@ -16,6 +16,9 @@ All test-projects are Qt-projects that use qmake to build. You can load them int
|
||||
<tr><td> \image html jkqtplotter_simpletest1_small.png
|
||||
<td> \subpage JKQTPlotterSimpleTest
|
||||
<td> `JKQTPXYLineGraph` <br> C++-style QVector arrays of data
|
||||
<tr><td> \image html scatter_small.png
|
||||
<td> \subpage JKQTPlotterscatter
|
||||
<td> `JKQTPXYScatterGraph` <br> Iterator-Interface for JKQTDatastore
|
||||
<tr><td> \image html speed_small.png
|
||||
<td> \subpage JKQTPlotterSpeedTest
|
||||
<td> `JKQTPXYLineGraph` <br> external `std::array<double,N>` data, not owned by datastore <br> live-data, measure plotting speed <br> tipps to increas plotting speed
|
||||
|
@ -82,6 +82,7 @@ add_subdirectory(rgbimageplot)
|
||||
add_subdirectory(rgbimageplot_cimg)
|
||||
add_subdirectory(rgbimageplot_opencv)
|
||||
add_subdirectory(rgbimageplot_qt)
|
||||
add_subdirectory(scatter)
|
||||
add_subdirectory(speed)
|
||||
add_subdirectory(stackedbars)
|
||||
add_subdirectory(stepplots)
|
||||
|
@ -8,6 +8,7 @@ All test-projects are Qt-projects that use qmake to build. You can load them int
|
||||
| Screenshot | Description | Notes |
|
||||
|:-------------:| ------------- | ------------- |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest1_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/simpletest/README.md) | [Very Basic Example (Line Graph)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/simpletest/README.md) | `JKQTPXYLineGraph` <br> C++-style QVector arrays of data |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/scatter_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/scatter/README.md) | [Very Basic Example (Scatter Graph)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/scatter/README.md) | `JKQTPXYScatterGraph` <br> Iterator-Interface for JKQTDatastore |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/speed_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/speed) | [Line Graph with Live Data / Speed Test](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/speed) | `JKQTPXYLineGraph` <br> external `std::array<double,N>` data, not owned by datastore <br> live-data, measure plotting speed <br> tipps to increas plotting speed |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/symbols_and_styles_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/symbols_and_styles) | [Line Graph with Different Symbols and Line Styles](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/symbols_and_styles) | `JKQTPXYLineGraph` <br> C++ vector of data <br> setting line styles and symbol styles <br> automatic graph coloring |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/stepplots_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/stepplots) | [Special Step Line Plots in Different Styles](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/stepplots) | `JKQTPSpecialLineHorizontalGraph` <br> C++ vector of data <br> different step modes, filled and line-only |
|
||||
|
33
examples/scatter/CMakeLists.txt
Normal file
33
examples/scatter/CMakeLists.txt
Normal file
@ -0,0 +1,33 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(EXAMPLE_NAME scatter)
|
||||
set(EXENAME jkqtptest_${EXAMPLE_NAME})
|
||||
|
||||
message( STATUS ".. Building Example ${EXAMPLE_NAME}" )
|
||||
|
||||
|
||||
# Set up source files
|
||||
set(SOURCES scatter.cpp )
|
||||
set(HEADERS )
|
||||
set(RESOURCES )
|
||||
set(UIS )
|
||||
|
||||
add_executable(${EXENAME} WIN32 ${SOURCES} ${HEADERS} ${RESOURCES} ${UIS})
|
||||
target_include_directories(${EXENAME} PRIVATE ../../lib)
|
||||
if(JKQtPlotter_BUILD_STATIC_LIBS)
|
||||
target_link_libraries(${EXENAME} JKQTPlotterLib)
|
||||
|
||||
elseif(JKQtPlotter_BUILD_SHARED_LIBS)
|
||||
target_link_libraries(${EXENAME} JKQTPlotterSharedLib)
|
||||
endif()
|
||||
target_link_libraries(${EXENAME} JKQTPExampleToolsLib)
|
||||
|
||||
# precomiled headers to speed up compilation
|
||||
target_precompile_headers(${EXENAME} PRIVATE ../../lib/jkqtplotter/private/jkqtplotter_precomp.h)
|
||||
|
||||
|
||||
# Installation
|
||||
install(TARGETS ${EXENAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
#Installation of Qt DLLs on Windows
|
||||
jkqtplotter_deployqt(${EXENAME})
|
57
examples/scatter/README.md
Normal file
57
examples/scatter/README.md
Normal file
@ -0,0 +1,57 @@
|
||||
# Example (JKQTPlotter): Very simple scatter-graph {#JKQTPlotterscatter}
|
||||
|
||||
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`](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/scatter/scatter.cpp).
|
||||
|
||||
First we create a plotter window and get a pointer to the internal datastore (for convenience):
|
||||
```.cpp
|
||||
JKQTPlotter plot;
|
||||
JKQTPDatastore* ds=plot.getDatastore();
|
||||
```
|
||||
Now we add two columns to the JKQTPDatastore and obtain back-inserter iterators for these:
|
||||
```.cpp
|
||||
size_t columnX=ds->addColumn("x");
|
||||
auto colXInserter=ds->backInserter(columnX);
|
||||
size_t columnY=ds->addColumn("y");
|
||||
auto colYInserter=ds->backInserter(columnY);
|
||||
```
|
||||
Now we create data for a simple plot (a sine curve with random noise):
|
||||
```.cpp
|
||||
std::default_random_engine generator;
|
||||
std::normal_distribution<double> distribution(0,0.5);
|
||||
const int Ndata=100;
|
||||
for (int i=0; i<Ndata; i++) {
|
||||
// put data
|
||||
const double x=double(i)/double(Ndata)*8.0*JKQTPSTATISTICS_PI;
|
||||
*colXInserter=x;
|
||||
*colYInserter=sin(x)+distribution(generator);
|
||||
// advance back-inserters
|
||||
colXInserter++;
|
||||
colYInserter++;
|
||||
}
|
||||
|
||||
```
|
||||
Here we create a graph in the plot, which plots the dataset X/Y:
|
||||
```.cpp
|
||||
JKQTPXYScatterGraph* graph1=new JKQTPXYScatterGraph(&plot);
|
||||
graph1->setXColumn(columnX);
|
||||
graph1->setYColumn(columnY);
|
||||
graph1->setTitle(QObject::tr("sine graph"));
|
||||
```
|
||||
Now we add the graph to the plot, so it is actually displayed:
|
||||
```.cpp
|
||||
plot.addGraph(graph1);
|
||||
```
|
||||
Finally we autoscale the plot so the graph is contained:
|
||||
```.cpp
|
||||
plot.zoomToFit();
|
||||
```
|
||||
The result looks like this:
|
||||
|
||||
![jkqtplotter_scatter](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/scatter.png)
|
||||
|
||||
|
||||
|
68
examples/scatter/scatter.cpp
Normal file
68
examples/scatter/scatter.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
/** \example scatter.cpp
|
||||
* A very basic example for the usage of JKQTPScatterGraphh
|
||||
*
|
||||
* \ref JKQTPlotterscatter
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
#include "jkqtplotter/graphs/jkqtpscatter.h"
|
||||
#include "jkqtpexampleapplication.h"
|
||||
#include <random>
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,6,0) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
|
||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // DPI support
|
||||
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); //HiDPI pixmaps
|
||||
#endif
|
||||
|
||||
JKQTPExampleApplication 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. add two columns to the JKQTPDatastore and obtain back-inserter iterators for these
|
||||
size_t columnX=ds->addColumn("x");
|
||||
auto colXInserter=ds->backInserter(columnX);
|
||||
size_t columnY=ds->addColumn("y");
|
||||
auto colYInserter=ds->backInserter(columnY);
|
||||
|
||||
// 3. 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++) {
|
||||
// put data
|
||||
const double x=double(i)/double(Ndata)*8.0*JKQTPSTATISTICS_PI;
|
||||
*colXInserter=x;
|
||||
*colYInserter=sin(x)+distribution(generator);
|
||||
// advance back-inserters
|
||||
colXInserter++;
|
||||
colYInserter++;
|
||||
}
|
||||
|
||||
|
||||
// 4. create a graph in the plot, which plots the dataset X/Y:
|
||||
JKQTPXYScatterGraph* graph1=new JKQTPXYScatterGraph(&plot);
|
||||
graph1->setXColumn(columnX);
|
||||
graph1->setYColumn(columnY);
|
||||
graph1->setTitle(QObject::tr("sine graph"));
|
||||
|
||||
// 5. add the graph to the plot, so it is actually displayed
|
||||
plot.addGraph(graph1);
|
||||
|
||||
// 6. autoscale the plot so the graph is contained
|
||||
plot.zoomToFit();
|
||||
|
||||
// show plotter and make it a decent size
|
||||
plot.getPlotter()->setPlotLabel(QObject::tr("Scatter Example"));
|
||||
plot.show();
|
||||
plot.resize(600,400);
|
||||
|
||||
return app.exec();
|
||||
}
|
30
examples/scatter/scatter.pro
Normal file
30
examples/scatter/scatter.pro
Normal file
@ -0,0 +1,30 @@
|
||||
# source code for this simple demo
|
||||
SOURCES = scatter.cpp
|
||||
|
||||
# add tools library
|
||||
include(../libexampletools/libexampletools.pri)
|
||||
|
||||
# configure Qt
|
||||
CONFIG += link_prl qt
|
||||
QT += core gui xml svg
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
|
||||
|
||||
# output executable name
|
||||
TARGET = scatter
|
||||
|
||||
# include JKQTPlotter source headers and link against library
|
||||
DEPENDPATH += ../../lib ../../qmake/staticlib/jkqtplotterlib
|
||||
INCLUDEPATH += ../../lib
|
||||
CONFIG (debug, debug|release) {
|
||||
LIBS += -L../../qmake/staticlib/jkqtplotterlib/debug -ljkqtplotterlib_debug
|
||||
} else {
|
||||
LIBS += -L../../qmake/staticlib/jkqtplotterlib/release -ljkqtplotterlib
|
||||
}
|
||||
message("LIBS = $$LIBS")
|
||||
|
||||
win32-msvc*: DEFINES += _USE_MATH_DEFINES
|
||||
win32-msvc*: DEFINES += NOMINMAX
|
||||
|
||||
|
||||
|
||||
|
8
examples/scatter/scatter_and_lib.pro
Normal file
8
examples/scatter/scatter_and_lib.pro
Normal file
@ -0,0 +1,8 @@
|
||||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS += jkqtplotterlib scatter
|
||||
|
||||
jkqtplotterlib.file = ../../qmake/staticlib/jkqtplotterlib/jkqtplotterlib.pro
|
||||
|
||||
scatter.file=$$PWD/scatter.pro
|
||||
scatter.depends = jkqtplotterlib
|
Loading…
Reference in New Issue
Block a user