JKQtPlotter/examples/scatter
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
README.md added Example for JKQTPXYScatterGraph and JKQTPXYScatterErrorGraph 2022-08-26 12:43:00 +02:00
scatter_and_lib.pro added Example for JKQTPXYScatterGraph and JKQTPXYScatterErrorGraph 2022-08-26 12:43:00 +02:00
scatter.cpp fixed issue #73: Symbol thickness differs in actual plot and legend 2022-08-30 09:44:40 +02:00
scatter.pro added Example for JKQTPXYScatterGraph and JKQTPXYScatterErrorGraph 2022-08-26 12:43:00 +02:00

Example (JKQTPlotter): Very simple scatter-graph

This project (see ./examples/scatter/) simply creates a JKQTPlotter widget (as a new window) and adds a single scatter graph of type JKQTPXYScatterGraph (a sine-wave with noise).

The source code of the example can be found in jkqtplotter_scatter.cpp.

First we create a plotter window and get a pointer to the internal datastore (for convenience):

    JKQTPlotter plot;
    JKQTPDatastore* ds=plot.getDatastore();

Now we add two columns to the JKQTPDatastore and obtain back-inserter iterators for these:

    size_t columnX=ds->addColumn("x");
    auto colXInserter=ds->backInserter(columnX);
    size_t columnY=ds->addColumn("y");
    auto colYInserter=ds->backInserter(columnY);

Now we create data for a simple plot (a sine curve with random noise):

    std::default_random_engine generator;
    std::normal_distribution<double> distribution(0,0.5);
    const int Ndata=100;
    for (int i=0; i<Ndata; i++) {
        // put data
        const double x=double(i)/double(Ndata)*8.0*JKQTPSTATISTICS_PI;
        *colXInserter=x;
        *colYInserter=sin(x)+distribution(generator);
        // advance back-inserters
        colXInserter++;
        colYInserter++;
    }

Here we create a graph in the plot, which plots the dataset X/Y:

    JKQTPXYScatterGraph* graph1=new JKQTPXYScatterGraph(&plot);
    graph1->setXColumn(columnX);
    graph1->setYColumn(columnY);
    graph1->setTitle(QObject::tr("sine graph"));

Now we add the graph to the plot, so it is actually displayed:

    plot.addGraph(graph1);

Finally we autoscale the plot so the graph is contained:

    plot.zoomToFit();

The result looks like this:

jkqtplotter_scatter