JKQtPlotter/test/jkqtplotter_simpletest_logaxes
2018-12-02 18:30:12 +01:00
..
jkqtplotter_simpletest_logaxes_and_lib.pro some bug-fixes (ressources from library were not loaded, compile order in projects was wrong) 2018-12-02 18:30:12 +01:00
jkqtplotter_simpletest_logaxes.cpp added example for log axes 2018-11-29 22:48:31 +01:00
jkqtplotter_simpletest_logaxes.pro some reorganizations + QMake-build-projects with library 2018-12-02 14:08:43 +01:00
README.md added example for log axes 2018-11-29 22:48:31 +01:00

Back to JKQTPlotter main page

JKQtPlotter

Line Graph with Logarithmic y-axis

This project (see ./test/jkqtplotter_simpletest_logaxes/) simply creates a JKQtPlotter widget (as a new window) and several line-graphs of different resonance curves.

The source code of the main application can be found in jkqtplotter_simpletest_logaxes.cpp. Mainly several graphs are generated in a loop and then different line styles are applied to the graphs (set by ``graph->set_style()`). The colors are set automtically from an internal default palette. The main loop looks like this:

	QVector<Qt::PenStyle> pens {Qt::SolidLine, Qt::DashLine, Qt::DotLine, Qt::DashDotLine, Qt::DashDotDotLine };
    for (int id=0; id<D.size(); id++) {
        // generate some plot data
        QVector<double> Y;
        for (auto& xx: X) {
            Y<<1.0/sqrt(sqr(1-sqr(xx))+sqr(2*xx*D[id]));
        }

        JKQTPxyLineGraph* graph=new JKQTPxyLineGraph(&plot);

        // copy data into datastore and immediately set the yColumn
        graph->set_xColumn(columnX);
        graph->set_yColumn(ds->addCopiedColumn(Y, "y"+QString::number(id)));

        // don't use symbols
        graph->set_symbol(JKQTPnoSymbol);
        // use one of different pens
        graph->set_style(pens[id%pens.size()]);
        // set width of graph line
        graph->set_lineWidth(1.5);

        // graph title is made from symbol+penstyle
        graph->set_title(QString("D=\\delta/\\omega_0=%1").arg(D[id]));

        // add the graph to the plot, so it is actually displayed
        plot.addGraph(graph);
    }

Then a JKQTPgeoText is added to the graph, which shows the function plotted in the plot:

    // 4. Also we add a text-element in the plot to show the plotted function
    //    This element (JKQTPgeoText) is taken from the set of geometric elements
    //    and is simply parametrized by a position (1.8/10) and the text to display.
    //    In addition you can also set the font size (here to 15)
    plot.addGraph(new JKQTPgeoText(&plot, 1.8, 10, "\\frac{A}{A_{stat}}=\\frac{1}{\\sqrt{\\left(1-\\eta^2\\right)^2+\\left(2{\\eta}D\\right)^2}}", 15));
    // for nicer rendering we set the fonts used by the internal LaTeX parser instance to XITS
    plot.get_plotter()->get_mathText()->useXITS();

Finally the y-axis is switched to logarithmic scaling and the axis labels are set:

    // 4. set y-axis to logarithmic (x-axis would be analogous)
    //    and set axis labels (using LaTeX notation)
    plot.get_yAxis()->set_logAxis(true);
    plot.get_yAxis()->set_axisLabel("Amplitude A/A_{stat}");
    plot.get_xAxis()->set_axisLabel("relative driving frequency \\eta=\\omega/\\omega_0");

The result looks like this:

jkqtplotter_simpletest_symbols_and_styles

Without the logarithmic scaling we would have:

jkqtplotter_simpletest_symbols_and_styles

Back to JKQTPlotter main page