JKQtPlotter/examples/impulsesplot
jkriege2 b0df7a1fd7 NEW/BREAKING: provide general targets JKQTPlotter5/6::JKQTPlotter5/6, JKQTPlotter5/6::JKQTMathText5/6, ... which are independent of the type of build (shared/static)
NEW/BREAKING: refactor CMake-Code, so static/dynamic switch is done via <code>BUILD_SHARED_LIBS</code>, which retires <code>JKQtPlotter_BUILD_STATIC_LIBS</code>, <code>JKQtPlotter_BUILD_SHARED_LIBS</code> and removes the capability to build static and shared libraries in one location (fixes issue #104)
NEW: prepareed library for CMake's <a href="https://cmake.org/cmake/help/latest/module/FetchContent.html">FetchContent</a>-API
NEW: the different sub-libraries JKQTPlotter, JKQTFastPlotter (DEPRECATED), JKQTMath, JKQTMathText can be activated/deactivated with CMake options JKQtPlotter_BUILD_LIB_JKQTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTFASTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTMATHTEXT, JKQtPlotter_BUILD_LIB_JKQTMATH
2024-01-16 13:07:08 +01:00
..
CMakeLists.txt NEW/BREAKING: provide general targets JKQTPlotter5/6::JKQTPlotter5/6, JKQTPlotter5/6::JKQTMathText5/6, ... which are independent of the type of build (shared/static) 2024-01-16 13:07:08 +01:00
impulsesplot_and_lib.pro using CMake now to build examples 2019-06-20 22:24:47 +02:00
impulsesplot.cpp NEW: barcharts and impulse graphs may now draw their baseline as stylable line (default: off) 2022-10-31 20:34:01 +01:00
impulsesplot.pro using CMake now to build examples 2019-06-20 22:24:47 +02:00
README.md using CMake now to build examples 2019-06-20 22:24:47 +02:00

Example (JKQTPlotter): Simple impulse plots

This project (see ./examples/impulsesplot/) simply creates a JKQTPlotter widget (as a new window) and adds a single impulse graph. The source code of the main application is (see impulsesplot.cpp.

First data for a curve is calculated and stored in QVector<double>:

    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);
    }

... and finally the data is copied into the datastore

    size_t columnX=ds->addCopiedColumn(X,  "x");
    size_t columnY=ds->addCopiedColumn(Y,  "y");

Now an impulse graph object is generated and added to the plot:

    JKQTPImpulsesVerticalGraph* graph=new JKQTPImpulsesVerticalGraph(&plot);
    graph->setXColumn(columnX);
    graph->setYColumn(columnY);
	graph->setLineWidth(2);
	graph->setColor(QColor("red"));
    graph->setTitle(QObject::tr("$\\cos(x)\\cdot\\exp(-x/10)$"));

    plot.addGraph(graph);

The result looks like this:

impulsesplot

There is an alternative class JKQTPImpulsesHorizontalGraph which draws horizontal impulse plots:

    JKQTPImpulsesHorizontalGraph* graph=new JKQTPImpulsesHorizontalGraph(&plot);
    graph->setYColumn(columnX);
    graph->setXColumn(columnY);
    graph->setLineWidth(2);
    graph->setColor(QColor("blue"));
    graph->setTitle(QObject::tr("$\\cos(x)\\cdot\\exp(-x/10)$"));

This code snippet results in a plot like this:

impulsesplot

The classes JKQTPImpulsesVerticalGraph and JKQTPImpulsesHorizontalGraph also provide the ability to draw a symbol at the end of the impulse, e.g. using this code:

    graph->setDrawSymbols(true);
    graph->setSymbolType(JKQTPGraphSymbols::JKQTPFilledStar);

This code snippet results in a plot like this:

impulsesplot_symbols

Finally you can move the baseline (i.e. the level, where the impulses start, which is typically x=0 or y=0) in the classes JKQTPImpulsesVerticalGraph and JKQTPImpulsesHorizontalGraph:

    graph->setBaseline(0.25);

This code snippet results in a plot like this:

impulsesplot_baseline