-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
70 lines (58 loc) · 1.91 KB
/
mainwindow.cpp
File metadata and controls
70 lines (58 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qcustomplot.h"
#include "spline.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QCustomPlot *customPlot = ui->widget;
std::vector<double> X = {10.0, 20.0, 25.0, 30.0, 50.0}; // must be increasing
std::vector<double> Y = {1550.0, 1552.0, 1555.0, 1550.0, 1551.0};
// origin data
{
QVector<double> x, y;
for (int i = 0; i < X.size(); ++i) {
x.append(X[i]);
y.append(Y[i]);
}
// create graph and assign data to it:
customPlot->addGraph();
customPlot->graph()->setPen(QColor(255, 0, 0));
customPlot->graph()->setLineStyle(QCPGraph::lsLine);
customPlot->graph()->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 5));
customPlot->graph()->setData(x, y);
customPlot->graph()->rescaleAxes(true);
// give the axes some labels:
customPlot->xAxis->setLabel("x");
customPlot->yAxis->setLabel("y");
// set axes ranges, so we see all data:
customPlot->xAxis->setRange(8.0, 52.0);
customPlot->yAxis->setRange(1545, 1560);
}
// cubic spline
{
tk::spline s(X, Y);
QVector<double> x, y;
for (int i = 10.0; i <= 50.0; i += 1) {
x.append(i);
y.append(s(i));
}
// create graph and assign data to it:
customPlot->addGraph();
customPlot->graph()->setPen(QColor(0, 0, 255));
customPlot->graph()->setData(x, y);
// give the axes some labels:
customPlot->xAxis->setLabel("x");
customPlot->yAxis->setLabel("y");
// set axes ranges, so we see all data:
customPlot->xAxis->setRange(8.0, 52.0);
customPlot->yAxis->setRange(1545, 1560);
}
customPlot->replot();
}
MainWindow::~MainWindow()
{
delete ui;
}