2019-01-13 01:53:16 +08:00
|
|
|
/** \example jkqtplotter_simpletest_impulsesplot.cpp
|
2019-01-20 23:15:10 +08:00
|
|
|
* Shows how to plot impulse graphs with JKQTPlotter
|
2019-01-13 01:53:16 +08:00
|
|
|
*
|
2019-01-20 23:15:10 +08:00
|
|
|
* \ref JKQTPlotterImpulsePlots
|
2019-01-13 01:53:16 +08:00
|
|
|
*/
|
|
|
|
|
2018-12-29 00:46:47 +08:00
|
|
|
#include <QApplication>
|
|
|
|
#include "jkqtplotter/jkqtplotter.h"
|
|
|
|
#include "jkqtplotter/jkqtpgraphsimpulses.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)
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPlotter plot;
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastore* ds=plot.getDatastore();
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// 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:
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPImpulsesVerticalGraph* graph=new JKQTPImpulsesVerticalGraph(&plot);
|
2019-01-26 20:00:40 +08:00
|
|
|
graph->setXColumn(columnX);
|
|
|
|
graph->setYColumn(columnY);
|
2019-01-26 03:16:04 +08:00
|
|
|
graph->setLineWidth(2);
|
2019-01-26 20:00:40 +08:00
|
|
|
graph->setColor(QColor("red"));
|
|
|
|
graph->setTitle(QObject::tr("$\\cos(x)\\cdot\\exp(-x/10)$"));
|
2019-04-22 19:27:50 +08:00
|
|
|
//graph->setDrawSymbols(true);
|
|
|
|
//graph->setSymbolType(JKQTPGraphSymbols::JKQTPFilledStar);
|
|
|
|
//graph->setBaseline(0.25);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// 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)
|
2019-01-26 03:16:04 +08:00
|
|
|
plot.getXAxis()->setAxisLabel(QObject::tr("x-axis"));
|
|
|
|
plot.getYAxis()->setAxisLabel(QObject::tr("y-axis"));
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// 7. switch the grid off
|
2019-01-26 20:00:40 +08:00
|
|
|
plot.getXAxis()->setDrawGrid(false);
|
|
|
|
plot.getYAxis()->setDrawGrid(false);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|