-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path00_graph_plot.cpp
More file actions
61 lines (48 loc) · 2.5 KB
/
Copy path00_graph_plot.cpp
File metadata and controls
61 lines (48 loc) · 2.5 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
#include "mainwindow.h"
#include <QDebug>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QDesktopWidget>
#endif
#include <QScreen>
#include <QMessageBox>
#include <QMetaEnum>
#include <fstream>
#include <iostream>
#include <vector>
#include <cmath>
// プロトタイプ宣言
void setting_labels(QCustomPlot *customPlot); // 軸ラベルを編集する。
void setting_legend(QCustomPlot *customPlot); // 凡例を編集する。
void setting_save_files(QCustomPlot *customPlot); // グラフの画像ファイルの編集をする。
// 関数設定(計算するのはこの部分)
void MainWindow::setupQuadraticDemo(QCustomPlot *customPlot)
{
demoName = "file_loading_and_drawing";
std::ofstream ost("graph_plot.csv"); // 出力フォルダの設定
int size = 100000;
// ベクトル定義部分
std::vector<double> x_1(size), y_1(size);
QVector<double> x(size), y(size); // グラフ出力用vector作成
// どうも定義する時点でゼロを準備する扱いになるらしい。
// データ解析用計算部分
for(int i=0; i<size; ++i){
x_1[i] = i * 0.001;
y_1[i] = std::pow(x_1[i], 2);
x[i] = x_1[i];
y[i] = y_1[i];
ost << x[i] << "\t" << y[i] <<"\n";
}
// グラフ作成部分
customPlot->addGraph();
customPlot->graph(0)->setData(x, y); // xとyはグラフ描画用の配列であることから他のvector配列とは別の扱いをする必要がある。
QPen blueDotPen; // ここで描画に関するクラスを作成する。
blueDotPen.setWidthF(4); // グラフの線幅指定
blueDotPen.setColor(QColor(0, 113, 189)); // 色指定(青バージョン)
//customPlot->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 6)); // プロット点をつける(基本的に大きさのみの指定をしている状態。色は指定しなくてもよい仕様のようです。)
customPlot->graph(0)->setPen(blueDotPen);
customPlot->graph(0)->setLineStyle(QCPGraph::lsLine); // lsNoneにすることで、データ間に実線を引かないようにする設定
customPlot->graph(0)->setName("graph plot");
setting_labels(customPlot); // 軸ラベルを編集する(別ファイルからの関数引用)
setting_legend(customPlot); // 凡例を編集する。
setting_save_files(customPlot); // 保存するファイルを設定する。
}