renamed impulse plot classes, so the names actually make sense

added example for impulse plots
This commit is contained in:
jkriege2 2018-12-11 23:00:43 +01:00
parent f5d4eb3190
commit 9debaae7fe
12 changed files with 218 additions and 40 deletions

View File

@ -45,6 +45,7 @@ addSimpleTest(symbols_and_styles)
addSimpleTest(filledgraphs)
addSimpleTest(speed)
addSimpleTest(rgbimageplot_qt)
addSimpleTest(impulsesplot)
#addSimpleTest(imageplot_nodatastore)
#addSimpleTest(rgbimageplot_opencv)
#addSimpleTest(imageplot_opencv)

View File

@ -26,6 +26,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/jkqtplotter_simpletest_barchart_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/simpletest_barchart) | [Simple Bar Charts](https://github.com/jkriege2/JKQtPlotter/tree/master/test/simpletest_barchart) | `JKQTPbarVerticalGraph`<br/>C-style arrays of data |
| [![](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) | `JKQTPbarVerticalGraph`<br/>setting/altering data in `JKQTPdatstore` directly<br/> transparent plots<br/>calculating histograms |
### Styling the Plot, Keys, Axes, ...

View File

@ -3173,13 +3173,13 @@ void JKQtBasePlotter::resetMasterSynchronization() {
size_t JKQtBasePlotter::addGraph(size_t xColumn, size_t yColumn, QString title, JKQTPgraphPlotstyle graphStyle) {
if (graphStyle==JKQTPimpulsesHorizontal) {
JKQTPimpulsesVerticalGraph* gr=new JKQTPimpulsesVerticalGraph(this);
JKQTPimpulsesHorizontalGraph* gr=new JKQTPimpulsesHorizontalGraph(this);
gr->set_title(title);
gr->set_xColumn(xColumn);
gr->set_yColumn(yColumn);
return addGraph(gr);
} else if (graphStyle==JKQTPimpulsesVertical) {
JKQTPimpulsesHorizontalGraph* gr=new JKQTPimpulsesHorizontalGraph(this);
JKQTPimpulsesVerticalGraph* gr=new JKQTPimpulsesVerticalGraph(this);
gr->set_title(title);
gr->set_xColumn(xColumn);
gr->set_yColumn(yColumn);
@ -3222,7 +3222,7 @@ size_t JKQtBasePlotter::addGraph(size_t xColumn, size_t yColumn, QString title,
size_t JKQtBasePlotter::addGraph(size_t xColumn, size_t yColumn, QString title, JKQTPgraphPlotstyle graphStyle, QColor color, JKQTPgraphSymbols symbol, Qt::PenStyle penstyle, double width) {
if (graphStyle==JKQTPimpulsesHorizontal) {
JKQTPimpulsesVerticalGraph* gr=new JKQTPimpulsesVerticalGraph(this);
JKQTPimpulsesHorizontalGraph* gr=new JKQTPimpulsesHorizontalGraph(this);
gr->set_title(title);
gr->set_xColumn(xColumn);
gr->set_yColumn(yColumn);
@ -3230,7 +3230,7 @@ size_t JKQtBasePlotter::addGraph(size_t xColumn, size_t yColumn, QString title,
gr->set_lineWidth(width);
return addGraph(gr);
} else if (graphStyle==JKQTPimpulsesVertical) {
JKQTPimpulsesHorizontalGraph* gr=new JKQTPimpulsesHorizontalGraph(this);
JKQTPimpulsesVerticalGraph* gr=new JKQTPimpulsesVerticalGraph(this);
gr->set_title(title);
gr->set_xColumn(xColumn);
gr->set_yColumn(yColumn);

View File

@ -34,7 +34,7 @@
JKQTPimpulsesVerticalGraph::JKQTPimpulsesVerticalGraph(JKQtBasePlotter* parent):
JKQTPimpulsesHorizontalGraph::JKQTPimpulsesHorizontalGraph(JKQtBasePlotter* parent):
JKQTPxyGraph(parent)
{
baseline=0;
@ -48,7 +48,7 @@ JKQTPimpulsesVerticalGraph::JKQTPimpulsesVerticalGraph(JKQtBasePlotter* parent):
}
}
JKQTPimpulsesVerticalGraph::JKQTPimpulsesVerticalGraph(JKQtPlotter* parent):
JKQTPimpulsesHorizontalGraph::JKQTPimpulsesHorizontalGraph(JKQtPlotter* parent):
JKQTPxyGraph(parent)
{
baseline=0;
@ -61,9 +61,9 @@ JKQTPimpulsesVerticalGraph::JKQTPimpulsesVerticalGraph(JKQtPlotter* parent):
color=parent->getPlotStyle(parentPlotStyle).color();
}
}
void JKQTPimpulsesVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
void JKQTPimpulsesHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
#ifdef JKQTBP_AUTOTIMER
JKQTPAutoOutputTimer jkaaot("JKQTPimpulsesVerticalGraph::draw");
JKQTPAutoOutputTimer jkaaot("JKQTPimpulsesHorizontalGraph::draw");
#endif
if (parent==nullptr) return;
JKQTPdatastore* datastore=parent->getDatastore();
@ -135,7 +135,7 @@ void JKQTPimpulsesVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
drawErrorsAfter(painter);
}
void JKQTPimpulsesVerticalGraph::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) {
void JKQTPimpulsesHorizontalGraph::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) {
painter.save();
@ -150,7 +150,7 @@ void JKQTPimpulsesVerticalGraph::drawKeyMarker(JKQTPEnhancedPainter& painter, QR
painter.restore();
}
QColor JKQTPimpulsesVerticalGraph::getKeyLabelColor() {
QColor JKQTPimpulsesHorizontalGraph::getKeyLabelColor() {
return color;
}
@ -164,20 +164,20 @@ QColor JKQTPimpulsesVerticalGraph::getKeyLabelColor() {
JKQTPimpulsesHorizontalGraph::JKQTPimpulsesHorizontalGraph(JKQtBasePlotter* parent):
JKQTPimpulsesVerticalGraph(parent)
JKQTPimpulsesVerticalGraph::JKQTPimpulsesVerticalGraph(JKQtBasePlotter* parent):
JKQTPimpulsesHorizontalGraph(parent)
{
}
JKQTPimpulsesHorizontalGraph::JKQTPimpulsesHorizontalGraph(JKQtPlotter *parent):
JKQTPimpulsesVerticalGraph(parent)
JKQTPimpulsesVerticalGraph::JKQTPimpulsesVerticalGraph(JKQtPlotter *parent):
JKQTPimpulsesHorizontalGraph(parent)
{
}
void JKQTPimpulsesHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
void JKQTPimpulsesVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
#ifdef JKQTBP_AUTOTIMER
JKQTPAutoOutputTimer jkaaot("JKQTPimpulsesHorizontalGraph::draw");
JKQTPAutoOutputTimer jkaaot("JKQTPimpulsesVerticalGraph::draw");
#endif
if (parent==nullptr) return;
JKQTPdatastore* datastore=parent->getDatastore();
@ -253,7 +253,7 @@ void JKQTPimpulsesHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
QPen JKQTPimpulsesVerticalGraph::getPen(JKQTPEnhancedPainter& painter) const {
QPen JKQTPimpulsesHorizontalGraph::getPen(JKQTPEnhancedPainter& painter) const {
QPen p;
p.setColor(color);
p.setWidthF(qMax(JKQTPLOTTER_ABS_MIN_LINEWIDTH,parent->pt2px(painter, parent->get_lineWidthMultiplier()*lineWidth)));
@ -263,9 +263,21 @@ QPen JKQTPimpulsesVerticalGraph::getPen(JKQTPEnhancedPainter& painter) const {
JKQTPimpulsesHorizontalErrorGraph::JKQTPimpulsesHorizontalErrorGraph(JKQtBasePlotter *parent):
JKQTPimpulsesHorizontalGraph(parent), JKQTPxGraphErrors()
{
setErrorColorFromGraphColor(color);
}
JKQTPimpulsesHorizontalErrorGraph::JKQTPimpulsesHorizontalErrorGraph(JKQtPlotter *parent):
JKQTPimpulsesHorizontalGraph(parent), JKQTPxGraphErrors()
{
setErrorColorFromGraphColor(color);
}
bool JKQTPimpulsesHorizontalErrorGraph::usesColumn(int c)
{
return JKQTPimpulsesVerticalGraph::usesColumn(c)|| JKQTPxGraphErrors::errorUsesColumn(c);
return JKQTPimpulsesHorizontalGraph::usesColumn(c)|| JKQTPxGraphErrors::errorUsesColumn(c);
}
void JKQTPimpulsesHorizontalErrorGraph::drawErrorsAfter(JKQTPEnhancedPainter &painter)
@ -275,20 +287,20 @@ void JKQTPimpulsesHorizontalErrorGraph::drawErrorsAfter(JKQTPEnhancedPainter &pa
}
JKQTPimpulsesVerticalErrorGraph::JKQTPimpulsesVerticalErrorGraph(JKQtBasePlotter *parent):
JKQTPimpulsesHorizontalGraph(parent), JKQTPyGraphErrors()
JKQTPimpulsesVerticalGraph(parent), JKQTPyGraphErrors()
{
setErrorColorFromGraphColor(color);
}
JKQTPimpulsesVerticalErrorGraph::JKQTPimpulsesVerticalErrorGraph(JKQtPlotter *parent):
JKQTPimpulsesHorizontalGraph(parent), JKQTPyGraphErrors()
JKQTPimpulsesVerticalGraph(parent), JKQTPyGraphErrors()
{
setErrorColorFromGraphColor(color);
}
bool JKQTPimpulsesVerticalErrorGraph::usesColumn(int c)
{
return JKQTPimpulsesHorizontalGraph::usesColumn(c)|| JKQTPyGraphErrors::errorUsesColumn(c);
return JKQTPimpulsesVerticalGraph::usesColumn(c)|| JKQTPyGraphErrors::errorUsesColumn(c);
}
void JKQTPimpulsesVerticalErrorGraph::drawErrorsAfter(JKQTPEnhancedPainter &painter)

View File

@ -26,18 +26,18 @@
/*! \brief This implements an impulse plot with impulses in direction of the X axis (i.e. from x=0 to x=f(y) )
/*! \brief This implements an impulse plot with impulses in direction of the X axis (i.e. from y=0 to y=f(x) )
\ingroup jkqtplotter_plots
\image html plot_impulsesxplots.png
*/
class LIB_EXPORT JKQTPimpulsesVerticalGraph: public JKQTPxyGraph {
class LIB_EXPORT JKQTPimpulsesHorizontalGraph: public JKQTPxyGraph {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPimpulsesVerticalGraph(JKQtBasePlotter* parent=nullptr);
JKQTPimpulsesHorizontalGraph(JKQtBasePlotter* parent=nullptr);
/** \brief class constructor */
JKQTPimpulsesVerticalGraph(JKQtPlotter* parent);
JKQTPimpulsesHorizontalGraph(JKQtPlotter* parent);
/** \brief plots the graph to the plotter object specified as parent */
virtual void draw(JKQTPEnhancedPainter& painter);
@ -72,20 +72,12 @@ class LIB_EXPORT JKQTPimpulsesVerticalGraph: public JKQTPxyGraph {
\image html plot_impulsesxerrorsplots.png
*/
class LIB_EXPORT JKQTPimpulsesHorizontalErrorGraph: public JKQTPimpulsesVerticalGraph, public JKQTPxGraphErrors {
class LIB_EXPORT JKQTPimpulsesHorizontalErrorGraph: public JKQTPimpulsesHorizontalGraph, public JKQTPxGraphErrors {
Q_OBJECT
public:
/** \brief class constructor */
inline JKQTPimpulsesHorizontalErrorGraph(JKQtBasePlotter* parent=nullptr):
JKQTPimpulsesVerticalGraph(parent), JKQTPxGraphErrors()
{
setErrorColorFromGraphColor(color);
}
inline JKQTPimpulsesHorizontalErrorGraph(JKQtPlotter* parent):
JKQTPimpulsesVerticalGraph(parent), JKQTPxGraphErrors()
{
setErrorColorFromGraphColor(color);
}
JKQTPimpulsesHorizontalErrorGraph(JKQtBasePlotter* parent=nullptr);
JKQTPimpulsesHorizontalErrorGraph(JKQtPlotter* parent);
/** \copydoc JKQTPgraph::usesColumn() */
virtual bool usesColumn(int c);
@ -103,13 +95,13 @@ class LIB_EXPORT JKQTPimpulsesHorizontalErrorGraph: public JKQTPimpulsesVertical
\image html plot_impulsesyplots.png
*/
class LIB_EXPORT JKQTPimpulsesHorizontalGraph: public JKQTPimpulsesVerticalGraph {
class LIB_EXPORT JKQTPimpulsesVerticalGraph: public JKQTPimpulsesHorizontalGraph {
Q_OBJECT
public:
/** \brief class constructor */
JKQTPimpulsesHorizontalGraph(JKQtBasePlotter* parent=nullptr);
JKQTPimpulsesVerticalGraph(JKQtBasePlotter* parent=nullptr);
/** \brief class constructor */
JKQTPimpulsesHorizontalGraph(JKQtPlotter* parent);
JKQTPimpulsesVerticalGraph(JKQtPlotter* parent);
/** \brief plots the graph to the plotter object specified as parent */
virtual void draw(JKQTPEnhancedPainter& painter);
@ -122,7 +114,7 @@ class LIB_EXPORT JKQTPimpulsesHorizontalGraph: public JKQTPimpulsesVerticalGraph
\image html plot_impulsesyerrorsplots.png
*/
class LIB_EXPORT JKQTPimpulsesVerticalErrorGraph: public JKQTPimpulsesHorizontalGraph, public JKQTPyGraphErrors {
class LIB_EXPORT JKQTPimpulsesVerticalErrorGraph: public JKQTPimpulsesVerticalGraph, public JKQTPyGraphErrors {
Q_OBJECT
public:
/** \brief class constructor */

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -0,0 +1,86 @@
[Back to JKQTPlotter main page](https://github.com/jkriege2/JKQtPlotter/)
# JKQtPlotter
## Simple impulse plots
This project (see `./test/simpletest_impulsesplot/`) simply creates a JKQtPlotter widget (as a new window) and adds a single impulse graph.
The soruce code of the main application is (see [`jkqtplotter_simpletest_impulsesplot.cpp`](https://github.com/jkriege2/JKQtPlotter/blob/master/test/simpletest_impulsesplot/jkqtplotter_simpletest_impulsesplot.cpp).
First the data columns for three x-y-curves are generated. One column of x-values with entries 0,1,2,...,254,255 (256 entries).
```c++
size_t columnX=ds->addLinearColumn(256, 0, 255, "x");
```
And three columns with 256 entries each, which will be filled with the R-, G- and B-histograms of an image `example.bmp`:
```c++
size_t columnR=ds->addColumn(256, "historam_R");
size_t columnG=ds->addColumn(256, "historam_G");
size_t columnB=ds->addColumn(256, "historam_B");
```
In this example we will access the data in the internal datastore directly. This access is possible through objects of type JKQTPcolumn, which is a proxy to the data in one of the columns in a `JKQTdatastore`:
```c++
JKQTPcolumn cG=ds->getColumn(columnG);
JKQTPcolumn cR=ds->getColumn(columnR);
JKQTPcolumn cB=ds->getColumn(columnB);
```
In order to calculate the histograms, first all entries in the columns are set to 0:
```c++
cR.setAll(0);
cG.setAll(0);
cB.setAll(0);
```
Finally the histogram is calculated:
```c++
QImage image(":/example.bmp");
for (int y=0; y<image.height(); y++) {
for (int x=0; x<image.width(); x++) {
QRgb pix=image.pixel(x,y);
cR.incValue(qRed(pix), 1);
cG.incValue(qGreen(pix), 1);
cB.incValue(qBlue(pix), 1);
}
}
cR.scale(100.0/static_cast<double>(image.width()*image.height()));
cG.scale(100.0/static_cast<double>(image.width()*image.height()));
cB.scale(100.0/static_cast<double>(image.width()*image.height()));
```
Finally three `JKQTPfilledCurveXGraph` objects are generated and added to the plot (here we show the code for the R-channel only):
```c++
JKQTPfilledCurveXGraph* graphR=new JKQTPfilledCurveXGraph(&plot);
// set graph titles
graphR->set_title("R-channel");
// set graph colors (lines: non-transparent, fill: semi-transparent
QColor col;
col=QColor("red"); graphR->set_color(col);
col.setAlphaF(0.25); graphR->set_fillColor(col);
// set data
graphR->set_xColumn(columnX); graphR->set_yColumn(columnR);
// add the graphs to the plot, so they are actually displayed
plot.addGraph(graphR);
```
The result looks like this:
![jkqtplotter_simpletest_impulsesplot](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_impulsesplot.png)
[Back to JKQTPlotter main page](https://github.com/jkriege2/JKQtPlotter/)

View File

@ -0,0 +1,55 @@
#include <QApplication>
#include "jkqtplotter/jkqtplotter.h"
#include "jkqtplotter/jkqtpimpulseselements.h"
// number of datapoints:
#define Ndata 40
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 data for a simple plot (a sine curve with lin. increasing errors)
QVector<double> X, Y;
for (int i=0; i<Ndata; i++) {
const double xx=double(i)/double(Ndata)*6.0*M_PI;
X << xx;
Y << cos(xx)*exp(-xx/10.0);
}
// 3. add data from vectors to the datastore
size_t columnX=ds->addCopiedColumn(X, "x");
size_t columnY=ds->addCopiedColumn(Y, "y");
// 4. create a vertical impulse graph in the plot, which plots the dataset X/Y:
JKQTPimpulsesVerticalGraph* graph=new JKQTPimpulsesVerticalGraph(&plot);
graph->set_xColumn(columnX);
graph->set_yColumn(columnY);
graph->set_lineWidth(2);
graph->set_color(QColor("red"));
graph->set_title(QObject::tr("$\\cos(x)\\cdot\\exp(-x/10)$"));
// 5. add the graph to the plot, so it is actually displayed
plot.addGraph(graph);
// 6. set some axis properties (we use LaTeX for nice equation rendering)
plot.getXAxis()->set_axisLabel(QObject::tr("x-axis"));
plot.getYAxis()->set_axisLabel(QObject::tr("y-axis"));
// 7. switch the grid off
plot.getXAxis()->set_drawGrid(false);
plot.getYAxis()->set_drawGrid(false);
// 8. autoscale the plot so the graph is contained
plot.zoomToFit();
// show plotter and make it a decent size
plot.show();
plot.resize(600,400);
return app.exec();
}

View File

@ -0,0 +1,23 @@
# source code for this simple demo
SOURCES = jkqtplotter_simpletest_impulsesplot.cpp
# configure Qt
CONFIG += qt
QT += core gui xml svg
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
# output executable name
TARGET = jkqtplotter_simpletest_impulsesplot
# 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

View File

@ -0,0 +1,8 @@
TEMPLATE = subdirs
SUBDIRS += jkqtplotterlib jkqtplotter_simpletest_impulsesplot
jkqtplotterlib.file = ../../lib/jkqtplotterlib.pro
jkqtplotter_simpletest_impulsesplot.file=$$PWD/jkqtplotter_simpletest_impulsesplot.pro
jkqtplotter_simpletest_impulsesplot.depends = jkqtplotterlib