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

Function main

lib/examples/example2/main.cpp:3–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include <labplot.h>
2
3int main(int argc, char** argv) {
4 // create a spreadsheet and import the data into it
5 auto* spreadsheet = new Spreadsheet(QStringLiteral("data"));
6 AsciiFilter filter;
7 filter.readDataFromFile(QStringLiteral("data.txt"), spreadsheet);
8
9 // create a worksheet
10 auto* worksheet = new Worksheet(QStringLiteral("worksheet"));
11
12 // create a plot area and add it to the worksheet
13 auto* plotArea = new CartesianPlot(QStringLiteral("plot area"));
14 plotArea->setType(CartesianPlot::Type::FourAxes);
15 plotArea->addLegend();
16 worksheet->addChild(plotArea);
17
18 // create a histogram for the imported data and add it to the plot area
19 auto* histogram = new Histogram(QStringLiteral("histogram"));
20 histogram->setNormalization(Histogram::Normalization::ProbabilityDensity);
21 histogram->setDataColumn(spreadsheet->column(0));
22 plotArea->addChild(histogram);
23
24 // perform a fit to the raw data and show it
25 auto* fitCurve = new XYFitCurve(QStringLiteral("fit"));
26 fitCurve->setDataSourceType(XYAnalysisCurve::DataSourceType::Histogram);
27 fitCurve->setDataSourceHistogram(histogram);
28 plotArea->addChild(histogram);
29
30 // initialize the fit
31 auto fitData = fitCurve->fitData();
32 fitData.modelCategory = nsl_fit_model_distribution;
33 fitData.modelType = nsl_sf_stats_gaussian;
34 fitData.algorithm = nsl_fit_algorithm_ml; // ML distribution fit
35 XYFitCurve::initFitData(fitData);
36 fitCurve->setFitData(fitData);
37
38 // perform the actual fit
39 fitCurve->recalculate();
40
41 // apply the theme "Dracula"
42 worksheet->setTheme(QStringLiteral("Dracula"));
43
44 // export the worksheet to PDF
45 worksheet->exportToFile(QStringLiteral("result.pdf"), Worksheet::ExportFormat::PDF);
46}

Callers

nothing calls this directly

Calls 13

addLegendMethod · 0.80
setNormalizationMethod · 0.80
setDataSourceTypeMethod · 0.80
readDataFromFileMethod · 0.45
setTypeMethod · 0.45
addChildMethod · 0.45
setDataColumnMethod · 0.45
columnMethod · 0.45
setFitDataMethod · 0.45
recalculateMethod · 0.45
setThemeMethod · 0.45

Tested by

no test coverage detected