JKQtPlotter/examples/simpletest_parametriccurve
2019-01-12 14:02:12 +01:00
..
jkqtplotter_simpletest_parametriccurve_and_lib.pro added example for geometric objects 2019-01-07 21:00:56 +01:00
jkqtplotter_simpletest_parametriccurve.cpp reorganized folder structure in root directory (there are now distinct folders for INCLUDE, STATIC, DYNAMIC libs and examples moved to the folder examples) 2018-12-28 17:46:47 +01:00
jkqtplotter_simpletest_parametriccurve.pro reorganized folder structure in root directory (there are now distinct folders for INCLUDE, STATIC, DYNAMIC libs and examples moved to the folder examples) 2018-12-28 17:46:47 +01:00
README.md improved readme-structure 2019-01-12 14:02:12 +01:00

Back to JKQTPlotter main page

JKQtPlotter

Plotting Parametric Curves

This project (see ./examples/simpletest_parametriccurve/) demonstrates how to draw parametric curves, using [JKQTPxyLineGraph}(../simpletest) and JKQTPxyParametrizedScatterGraph.

The source code of the main application can be found in jkqtplotter_simpletest_parametriccurve.cpp. First, the parametric curve (here a logarithic spiral) is sampled into two columns containing the x- and y-values along the curve. In addition the radial distance from x=y=0 is added into a third column:

    QVector<double> X, Y, R;
    const int Ndata=500; // number of plot points in each curve
    const double phiMax=4.0*M_PI;
    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");

Then simples graph just uses the columns X and Y to plot the curve:

    JKQTPxyLineGraph* graph1=new JKQTPxyLineGraph(&plot);
    graph1->set_xColumn(columnX);
    graph1->set_yColumn(columnY);
    graph1->set_drawLine(true);
    graph1->set_symbol(JKQTPnoSymbol);
    graph1->set_title("one-colored spiral");
    plot.addGraph(graph1);

If you use JKQTPxyParametrizedScatterGraph instead of JKQTPxyLineGraph, you can also modify the color of the line-segments, connecting the datapoints:

    JKQTPxyParametrizedScatterGraph* graph2=new JKQTPxyParametrizedScatterGraph(&plot2);
    graph2->set_xColumn(columnX);
    graph2->set_yColumn(columnY);
    graph2->set_colorColumn(columnR);
    graph2->set_palette(JKQTPMathImageMATLAB);
    graph2->set_symbol(JKQTPnoSymbol);
    graph2->set_drawLine(true);
    graph2->set_title("colored spiral");
    graph2->get_colorBarRightAxis()->set_axisLabel("color scale radius $r(\\phi)$");
    plot2.addGraph(graph2);

The result looks like this:

jkqtplotter_simpletest_parametriccurve

... and with the line-color set by the radius:

jkqtplotter_simpletest_parametriccurve

Back to JKQTPlotter main page