2019-06-21 04:24:47 +08:00
|
|
|
/** \example parametriccurve.cpp
|
2019-01-20 23:15:10 +08:00
|
|
|
* Shows how to plot parametric curves from datapoints with JKQTPlotter
|
2019-01-13 01:53:16 +08:00
|
|
|
*
|
2019-01-20 23:15:10 +08:00
|
|
|
* \ref JKQTPlotterParametricCurves
|
2019-01-13 01:53:16 +08:00
|
|
|
*/
|
|
|
|
|
2018-12-29 00:46:47 +08:00
|
|
|
#include <QApplication>
|
|
|
|
#include "jkqtplotter/jkqtplotter.h"
|
2019-06-20 22:06:31 +08:00
|
|
|
#include "jkqtplotter/graphs/jkqtpscatter.h"
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2022-04-16 05:01:09 +08:00
|
|
|
|
2022-04-22 19:27:31 +08:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5,6,0) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
|
|
|
|
|
2022-04-16 05:01:09 +08:00
|
|
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // DPI support
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); //HiDPI pixmaps
|
|
|
|
#endif
|
2018-12-29 00:46:47 +08:00
|
|
|
QApplication app(argc, argv);
|
|
|
|
|
2022-04-16 05:01:09 +08:00
|
|
|
|
2018-12-29 00:46:47 +08:00
|
|
|
// 1. create two plotter windows that share the same internal datastore (for convenience)
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPlotter plot, plot2;
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastore* ds=plot.getDatastore();
|
2018-12-29 00:46:47 +08:00
|
|
|
plot2.useExternalDatastore(ds);
|
|
|
|
|
|
|
|
// 2. now we create a vector of x- and y-values of the logarithmic spiral
|
|
|
|
// in addition the radius is stored in column R
|
|
|
|
QVector<double> X, Y, R;
|
|
|
|
const int Ndata=500; // number of plot points in each curve
|
2019-11-24 17:42:44 +08:00
|
|
|
const double phiMax=4.0*JKQTPSTATISTICS_PI;
|
2018-12-29 00:46:47 +08:00
|
|
|
const double a=1;
|
|
|
|
const double k=0.2;
|
|
|
|
for (double phi=-phiMax; phi<=phiMax; phi+=phiMax/double(Ndata)) {
|
|
|
|
const double x=a*exp(k*phi)*cos(phi);
|
|
|
|
const double y=a*exp(k*phi)*sin(phi);
|
|
|
|
X<<x;
|
|
|
|
Y<<y;
|
|
|
|
R<<sqrt(x*x+y*y);
|
|
|
|
}
|
|
|
|
// and copy it to the datastore
|
|
|
|
size_t columnX=ds->addCopiedColumn(X, "x");
|
|
|
|
size_t columnY=ds->addCopiedColumn(Y, "y");
|
|
|
|
size_t columnR=ds->addCopiedColumn(R, "r");
|
|
|
|
|
|
|
|
|
|
|
|
// 3. now we make several graphs. In each one, another property of the graph is controlled by
|
|
|
|
// a datacolumn
|
|
|
|
|
|
|
|
// 3.1 the basic graph
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPXYLineGraph* graph1=new JKQTPXYLineGraph(&plot);
|
2019-01-26 20:00:40 +08:00
|
|
|
graph1->setXColumn(columnX);
|
|
|
|
graph1->setYColumn(columnY);
|
|
|
|
graph1->setDrawLine(true);
|
2019-04-22 19:27:50 +08:00
|
|
|
graph1->setSymbolType(JKQTPNoSymbol);
|
2019-01-26 20:00:40 +08:00
|
|
|
graph1->setTitle("one-colored spiral");
|
2018-12-29 00:46:47 +08:00
|
|
|
plot.addGraph(graph1);
|
|
|
|
|
|
|
|
// 3.2 for graph2 is the same as graph 1, but in addition, the color of the lines
|
|
|
|
// is set, based on the contents of column R, via the color-palette JKQTPMathImageMATLAB
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPXYParametrizedScatterGraph* graph2=new JKQTPXYParametrizedScatterGraph(&plot2);
|
2019-01-26 20:00:40 +08:00
|
|
|
graph2->setXColumn(columnX);
|
|
|
|
graph2->setYColumn(columnY);
|
|
|
|
graph2->setColorColumn(columnR);
|
2020-09-11 18:14:51 +08:00
|
|
|
graph2->setColorPalette(JKQTPMathImageMATLAB);
|
2019-04-22 19:27:50 +08:00
|
|
|
graph2->setSymbolType(JKQTPNoSymbol);
|
2019-01-26 20:00:40 +08:00
|
|
|
graph2->setDrawLine(true);
|
|
|
|
graph2->setTitle("colored spiral");
|
|
|
|
graph2->getColorBarRightAxis()->setAxisLabel("color scale radius $r(\\phi)$");
|
2018-12-29 00:46:47 +08:00
|
|
|
plot2.addGraph(graph2);
|
|
|
|
|
|
|
|
|
|
|
|
// 4. set the axis scale aspect ratios to 1,
|
|
|
|
// autoscale the plot so the graph is contained
|
|
|
|
// and format the coordinate system and key
|
2019-01-26 03:16:04 +08:00
|
|
|
plot.getPlotter()->setMaintainAspectRatio(true);
|
|
|
|
plot.getPlotter()->setAspectRatio(1);
|
|
|
|
plot.getXAxis()->setAxisLabel("x-axis");
|
|
|
|
plot.getYAxis()->setAxisLabel("y-axis");
|
2019-01-26 20:00:40 +08:00
|
|
|
plot.getXAxis()->setDrawGrid(false);
|
|
|
|
plot.getYAxis()->setDrawGrid(false);
|
2018-12-29 00:46:47 +08:00
|
|
|
plot.setXY(-15,15,-15,15);
|
2019-01-26 03:16:04 +08:00
|
|
|
plot2.getPlotter()->setMaintainAspectRatio(true);
|
|
|
|
plot2.getPlotter()->setAspectRatio(1);
|
|
|
|
plot2.getXAxis()->setAxisLabel("x-axis");
|
|
|
|
plot2.getYAxis()->setAxisLabel("y-axis");
|
2019-01-26 20:00:40 +08:00
|
|
|
plot2.getXAxis()->setDrawGrid(false);
|
|
|
|
plot2.getYAxis()->setDrawGrid(false);
|
2018-12-29 00:46:47 +08:00
|
|
|
plot2.setXY(-15,15,-15,15);
|
|
|
|
|
|
|
|
|
|
|
|
// 5. show plotters and make them a decent size
|
|
|
|
plot.show();
|
|
|
|
plot.resize(600,600);
|
|
|
|
plot2.show();
|
|
|
|
plot2.resize(600,600);
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|