MCPcopy Create free account
hub / github.com/KDE/labplot / main

Function main

lib/examples/example1/main.cpp:7–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include <labplot.h>
6
7int main(int argc, char** argv) {
8 QApplication app(argc, argv);
9
10 auto* mainWidget = new QWidget();
11 auto* layout = new QHBoxLayout;
12 mainWidget->setLayout(layout);
13
14 // create a worksheet and a plot
15 auto* worksheet = new Worksheet(QStringLiteral("test"));
16
17 // create a plot
18 auto* plot = new CartesianPlot(QStringLiteral("plot"));
19 plot->setType(CartesianPlot::Type::FourAxes);
20 worksheet->addChild(plot);
21
22 // Generate some data for f(x) = a*x^2 + b*x + c with additional noise
23 int count = 10;
24 double a = 1.27;
25 double b = 4.375;
26 double c = -6.692;
27
28 auto* x = new Column(QStringLiteral("x"));
29 auto* y = new Column(QStringLiteral("y"));
30
31 for (int i = 0; i < count; ++i) {
32 x->setValueAt(i, i);
33 double rand_value = 10 * double(rand()) / double(RAND_MAX);
34 double value = a * pow(i, 2) + b * i + c + rand_value;
35 y->setValueAt(i, value);
36 }
37
38 auto* curve = new XYCurve(QStringLiteral("raw data"));
39 curve->setXColumn(x);
40 curve->setYColumn(y);
41 // curve->setLineStyle(XYCurve::LineStyle::NoLine);
42 // curve->symbol()->setStyle(Symbol::Circle);
43 plot->addChild(curve);
44
45 // perform a fit to the raw data and show it
46 auto* fitCurve = new XYFitCurve(QStringLiteral("fit"));
47 // TODO:
48 fitCurve->recalculate();
49 plot->addChild(fitCurve);
50
51 // add a curve defined via a mathematical equation
52 auto* eqCurve = new XYEquationCurve(QStringLiteral("eq"));
53 plot->addChild(eqCurve);
54 auto data = XYEquationCurve::EquationData();
55 data.expression1 = QStringLiteral("50*sin(x)");
56 data.min = QStringLiteral("0.0");
57 data.max = QStringLiteral("10.0");
58 eqCurve->setEquationData(data);
59 eqCurve->recalculate();
60
61 // add legend
62 plot->addLegend();
63
64 // create another plot

Callers

nothing calls this directly

Calls 15

EquationDataClass · 0.85
setLayoutMethod · 0.80
setYColumnMethod · 0.80
setEquationDataMethod · 0.80
addLegendMethod · 0.80
showMethod · 0.80
execMethod · 0.80
setTypeMethod · 0.45
addChildMethod · 0.45
setValueAtMethod · 0.45
setXColumnMethod · 0.45
recalculateMethod · 0.45

Tested by

no test coverage detected