forked from Cryoris/matplotlib-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsemilogy.cpp
More file actions
37 lines (29 loc) · 856 Bytes
/
semilogy.cpp
File metadata and controls
37 lines (29 loc) · 856 Bytes
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
#define _USE_MATH_DEFINES
#include "matplotlibcpp.h"
#include <Eigen/Dense>
#include <cmath>
#include <iostream>
namespace plt = matplotlibcpp;
int main() {
// Prepare data.
int n = 5000;
Eigen::VectorXd x(n), y(n), z(n), w = Eigen::VectorXd::Ones(n);
for (int i = 0; i < n; ++i) {
double value = (1.0 + i) / n;
x(i) = value;
y(i) = value * value;
z(i) = value * value * value;
}
// Plot line from given x and y data. Color is selected automatically.
plt::semilogy(x, y);
// Plot a red dashed line from given x and y data.
plt::semilogy(x, w, {{"c", "r"}, {"ls", "--"}});
// Plot a line whose name will show up as "log(x)" in the legend.
plt::semilogy(x, z, "g:", {{"label", "$x^3$"}});
// Add graph title
plt::title("Sample figure");
// Enable legend.
plt::legend();
// show figure
plt::show();
}