Skip to content

Commit 377ac84

Browse files
committed
add eigen semilog examples
1 parent c276668 commit 377ac84

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ eigen_include = -I /usr/local/include/eigen3
1818

1919
examples: minimal basic modern animation nonblock xkcd quiver bar surface subplot fill_inbetween fill update
2020

21-
eigen: eigen_basic eigen_modern eigen_loglog
21+
eigen: eigen_basic eigen_modern eigen_loglog eigen_semilogx eigen_semilogy
2222

2323
minimal: examples/minimal.cpp matplotlibcpp.h
2424
cd examples && g++ -DWITHOUT_NUMPY minimal.cpp ${includes} ${linkings} -o minimal ${definitions}
@@ -69,6 +69,12 @@ eigen_modern: examples/eigen/modern.cpp matplotlibcpp.h
6969
eigen_loglog: examples/eigen/loglog.cpp matplotlibcpp.h
7070
cd examples/eigen && g++ loglog.cpp ${includes} ${eigen_include} ${linkings} -o $@ ${definitions}
7171

72+
eigen_semilogx: examples/eigen/semilogx.cpp matplotlibcpp.h
73+
cd examples/eigen && g++ semilogx.cpp ${includes} ${eigen_include} ${linkings} -o $@ ${definitions}
74+
75+
eigen_semilogy: examples/eigen/semilogy.cpp matplotlibcpp.h
76+
cd examples/eigen && g++ semilogy.cpp ${includes} ${eigen_include} ${linkings} -o $@ ${definitions}
77+
7278
clean:
7379
rm -f examples/{minimal,basic,modern,animation,nonblock,xkcd,quiver,bar,surface,subplot,fill_inbetween,fill,update}
7480
rm -f examples/eigen/{eigen_basic,eigen_modern,eigen_loglog}

examples/eigen/semilogx.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#define _USE_MATH_DEFINES
2+
#include "../../matplotlibcpp.h"
3+
#include <Eigen/Dense>
4+
#include <cmath>
5+
#include <iostream>
6+
7+
namespace plt = matplotlibcpp;
8+
9+
int main() {
10+
// Prepare data.
11+
int n = 5000;
12+
Eigen::VectorXd x(n), y(n), z(n), w = Eigen::VectorXd::Ones(n);
13+
for (int i = 0; i < n; ++i) {
14+
double value = (1.0 + i) / n;
15+
x(i) = value;
16+
y(i) = value * value;
17+
z(i) = value * value * value;
18+
}
19+
20+
// Plot line from given x and y data. Color is selected automatically.
21+
plt::semilogx(x, y);
22+
23+
// Plot a red dashed line from given x and y data.
24+
plt::semilogx(x, w, "r--");
25+
26+
// Plot a line whose name will show up as "log(x)" in the legend.
27+
plt::semilogx(x, z, "g:", {{"label", "$x^3$"}});
28+
29+
// Add graph title
30+
plt::title("Sample figure");
31+
32+
// Enable legend.
33+
plt::legend();
34+
35+
// show figure
36+
plt::show();
37+
}

examples/eigen/semilogy.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#define _USE_MATH_DEFINES
2+
#include "../../matplotlibcpp.h"
3+
#include <Eigen/Dense>
4+
#include <cmath>
5+
#include <iostream>
6+
7+
namespace plt = matplotlibcpp;
8+
9+
int main() {
10+
// Prepare data.
11+
int n = 5000;
12+
Eigen::VectorXd x(n), y(n), z(n), w = Eigen::VectorXd::Ones(n);
13+
for (int i = 0; i < n; ++i) {
14+
double value = (1.0 + i) / n;
15+
x(i) = value;
16+
y(i) = value * value;
17+
z(i) = value * value * value;
18+
}
19+
20+
// Plot line from given x and y data. Color is selected automatically.
21+
plt::semilogy(x, y);
22+
23+
// Plot a red dashed line from given x and y data.
24+
plt::semilogy(x, w, {{"c", "r"}, {"ls", "--"}});
25+
26+
// Plot a line whose name will show up as "log(x)" in the legend.
27+
plt::semilogy(x, z, "g:", {{"label", "$x^3$"}});
28+
29+
// Add graph title
30+
plt::title("Sample figure");
31+
32+
// Enable legend.
33+
plt::legend();
34+
35+
// show figure
36+
plt::show();
37+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy