JKQtPlotter/examples/simpletest_parametriccurve
jkriege2 a67975e680 - major rework of graph styling (now using mix-in classes)
- some reorganizations into different files
- additional options for graph filling (color gradients, textures, ...) as provided by QBrush
- PREPARATIONS: added a general feature to JKQTPPlotElement which allows to show a graph in a highlighted state (if supported by the derived graph class!)
- JKQTPXYParametrizedScatterGraph: added functors to transform column values into symbol type+size and line-width to give even more control
- JKQTPStepHorizontalGraph has been renamed to JKQTPSpecialLineHorizontalGraph (vertical variants also) and have gained additional features (baseline for filling and drawing of symbols)
- filled curve graphs (e.g. JKQTPSpecialLineHorizontalGraph) are now merely a specializedly initialized JKQTPSpecialLineHorizontalGraph
2019-04-22 13:27:50 +02:00
..
jkqtplotter_simpletest_parametriccurve_and_lib.pro moved build-projects for libs into their own subdirectories (works better with QMake, when building different libs) + necessary docu updates 2019-02-09 15:25:16 +01:00
jkqtplotter_simpletest_parametriccurve.cpp - major rework of graph styling (now using mix-in classes) 2019-04-22 13:27:50 +02:00
jkqtplotter_simpletest_parametriccurve.pro moved build-projects for libs into their own subdirectories (works better with QMake, when building different libs) + necessary docu updates 2019-02-09 15:25:16 +01:00
README.md - major rework of graph styling (now using mix-in classes) 2019-04-22 13:27:50 +02:00

Example (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->setXColumn(columnX);
    graph1->setYColumn(columnY);
    graph1->setDrawLine(true);
    graph1->setSymbolType(JKQTPNoSymbol);
    graph1->setTitle("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->setXColumn(columnX);
    graph2->setYColumn(columnY);
    graph2->setColorColumn(columnR);
    graph2->setPalette(JKQTPMathImageMATLAB);
    graph2->setSymbolType(JKQTPNoSymbol);
    graph2->setDrawLine(true);
    graph2->setTitle("colored spiral");
    graph2->getColorBarRightAxis()->setAxisLabel("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