pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/ScientificC/matplotlib-cpp/commit/ae6bb28837fb1993909a6332fb39196d65e64d94

nonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/global-95af332f763e4560.css" /> Added examples · ScientificC/matplotlib-cpp@ae6bb28 · GitHub
Skip to content

Commit ae6bb28

Browse files
Added examples
1 parent 00a4766 commit ae6bb28

File tree

8 files changed

+55
-44
lines changed

8 files changed

+55
-44
lines changed

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
examples: minimal basic modern animation nonblock xkcd quiver
22

33
minimal: examples/minimal.cpp matplotlibcpp.h
4-
cd examples && g++ -DWITHOUT_NUMPY minimal.cpp -I/usr/include/python2.7 -lpython2.7 -o minimal -std=c++11
4+
cd examples && g++ -DWITHOUT_NUMPY minimal.cpp -I/usr/lib/python3.7/site-packages/numpy/core/include -I/usr/include/python3.7m -lpython3.7m -lcml -o minimal.o -std=c++11
55

66
basic: examples/basic.cpp matplotlibcpp.h
7-
cd examples && g++ basic.cpp -I/usr/include/python2.7 -lpython2.7 -o basic
7+
cd examples && g++ basic.cpp -I/usr/lib/python3.7/site-packages/numpy/core/include -I/usr/include/python3.7m -lpython3.7m -lcml -o basic
88

99
modern: examples/modern.cpp matplotlibcpp.h
10-
cd examples && g++ modern.cpp -I/usr/include/python2.7 -lpython2.7 -o modern -std=c++11
10+
cd examples && g++ modern.cpp -I/usr/lib/python3.7/site-packages/numpy/core/include -I/usr/include/python3.7m -lpython3.7m -lcml -o modern.o -std=c++11
1111

1212
animation: examples/animation.cpp matplotlibcpp.h
13-
cd examples && g++ animation.cpp -I/usr/include/python2.7 -lpython2.7 -o animation -std=c++11
13+
cd examples && g++ animation.cpp -I/usr/lib/python3.7/site-packages/numpy/core/include -I/usr/include/python3.7m -lpython3.7m -lcml -o animation.o -std=c++11
1414

1515
nonblock: examples/nonblock.cpp matplotlibcpp.h
16-
cd examples && g++ nonblock.cpp -I/usr/include/python2.7 -lpython2.7 -o nonblock -std=c++11
16+
cd examples && g++ nonblock.cpp -I/usr/lib/python3.7/site-packages/numpy/core/include -I/usr/include/python3.7m -lpython3.7m -lcml -o nonblock.o -std=c++11
1717

1818
quiver: examples/quiver.cpp matplotlibcpp.h
19-
cd examples && g++ quiver.cpp -I/usr/include/python2.7 -lpython2.7 -o quiver -std=c++11
19+
cd examples && g++ quiver.cpp -I/usr/lib/python3.7/site-packages/numpy/core/include -I/usr/include/python3.7m -lpython3.7m -lcml -o quiver.o -std=c++11
2020

2121
xkcd: examples/xkcd.cpp matplotlibcpp.h
22-
cd examples && g++ xkcd.cpp -I/usr/include/python2.7 -lpython2.7 -o xkcd -std=c++11
22+
cd examples && g++ xkcd.cpp -I/usr/lib/python3.7/site-packages/numpy/core/include -I/usr/include/python3.7m -lpython3.7m -lcml -o xkcd.o -std=c++11
2323

2424
clean:
2525
rm -f examples/{minimal,basic,modern,animation,nonblock,xkcd,quiver}

examples/animation.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#define _USE_MATH_DEFINES
2-
#include <cmath>
2+
3+
#include <cml/math.h>
34
#include "../matplotlibcpp.h"
45

56
namespace plt = matplotlibcpp;
@@ -9,12 +10,14 @@ int main()
910
int n = 1000;
1011
std::vector<double> x, y, z;
1112

12-
for(int i=0; i<n; i++) {
13-
x.push_back(i*i);
14-
y.push_back(sin(2*M_PI*i/360.0));
15-
z.push_back(log(i));
13+
for (int i = 0; i < n; i++)
14+
{
15+
x.push_back(i * i);
16+
y.push_back(cml_sin(2 * M_PI * i/360.0));
17+
z.push_back(cml_log(i));
1618

17-
if (i % 10 == 0) {
19+
if (i % 10 == 0)
20+
{
1821
// Clear previous plot
1922
plt::clf();
2023
// Plot line from given x and y data. Color is selected automatically.
@@ -23,7 +26,7 @@ int main()
2326
plt::named_plot("log(x)", x, z);
2427

2528
// Set x-axis to interval [0,1000000]
26-
plt::xlim(0, n*n);
29+
plt::xlim(0, n * n);
2730

2831
// Add graph title
2932
plt::title("Sample figure");

examples/basic.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define _USE_MATH_DEFINES
22
#include <iostream>
3-
#include <cmath>
3+
#include <cml/math.h>
44
#include "../matplotlibcpp.h"
55

66
namespace plt = matplotlibcpp;
@@ -10,10 +10,11 @@ int main()
1010
// Prepare data.
1111
int n = 5000;
1212
std::vector<double> x(n), y(n), z(n), w(n,2);
13-
for(int i=0; i<n; ++i) {
13+
for (int i = 0; i < n; ++i)
14+
{
1415
x.at(i) = i*i;
15-
y.at(i) = sin(2*M_PI*i/360.0);
16-
z.at(i) = log(i);
16+
y.at(i) = cml_sin(2*M_PI*i/360.0);
17+
z.at(i) = cml_log(i);
1718
}
1819

1920
// Set the size of output image = 1200x780 pixels

examples/fill_inbetween.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
#define _USE_MATH_DEFINES
2+
23
#include "../matplotlibcpp.h"
3-
#include <cmath>
4+
#include <cml/math.h>
45
#include <iostream>
56

67
using namespace std;
78
namespace plt = matplotlibcpp;
89

9-
int main() {
10+
int main()
11+
{
1012
// Prepare data.
1113
int n = 5000;
1214
std::vector<double> x(n), y(n), z(n), w(n, 2);
13-
for (int i = 0; i < n; ++i) {
15+
for (int i = 0; i < n; ++i)
16+
{
1417
x.at(i) = i * i;
15-
y.at(i) = sin(2 * M_PI * i / 360.0);
16-
z.at(i) = log(i);
18+
y.at(i) = cml_sin(2 * M_PI * i / 360.0);
19+
z.at(i) = cml_log(i);
1720
}
1821

1922
// Prepare keywords to pass to PolyCollection. See

examples/modern.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#define _USE_MATH_DEFINES
2-
#include <cmath>
2+
3+
#include <cml/math.h>
34
#include "../matplotlibcpp.h"
45

56
using namespace std;
@@ -12,18 +13,19 @@ int main()
1213

1314
// Prepare data for parametric plot.
1415
int n = 5000; // number of data points
15-
vector<double> x(n),y(n);
16-
for(int i=0; i<n; ++i) {
17-
double t = 2*M_PI*i/n;
18-
x.at(i) = 16*sin(t)*sin(t)*sin(t);
19-
y.at(i) = 13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t);
16+
vector<double> x(n), y(n);
17+
18+
for (int i = 0; i < n; ++i)
19+
{
20+
double t = 2 * M_PI * i/n;
21+
x.at(i) = 16 * cml_sin(t) * cml_sin(t) * cml_sin(t);
22+
y.at(i) = 13 * cml_cos(t) - 5 * cml_cos(2 * t) - 2 * cml_cos(3 * t) - cml_cos(4 * t);
2023
}
2124

2225
// plot() takes an arbitrary number of (x,y,format)-triples.
2326
// x must be iterable (that is, anything providing begin(x) and end(x)),
2427
// y must either be callable (providing operator() const) or iterable.
25-
plt::plot(x, y, "r-", x, [](double d) { return 12.5+abs(sin(d)); }, "k-");
26-
28+
plt::plot(x, y, "r-", x, [](double d) { return 12.5 + cml_abs(cml_sin(d)); }, "k-");
2729

2830
// show plots
2931
plt::show();

examples/nonblock.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#define _USE_MATH_DEFINES
2-
#include <cmath>
2+
#include <cml/math.h>
33
#include "../matplotlibcpp.h"
44

55
namespace plt = matplotlibcpp;
66

7-
87
using namespace matplotlibcpp;
98
using namespace std;
109

@@ -13,10 +12,11 @@ int main()
1312
// Prepare data.
1413
int n = 5000;
1514
std::vector<double> x(n), y(n), z(n), w(n,2);
16-
for(int i=0; i<n; ++i) {
15+
16+
for (int i=0; i<n; ++i) {
1717
x.at(i) = i*i;
18-
y.at(i) = sin(2*M_PI*i/360.0);
19-
z.at(i) = log(i);
18+
y.at(i) = cml_sin(2*M_PI*i/360.0);
19+
z.at(i) = cml_log(i);
2020
}
2121

2222
// Plot line from given x and y data. Color is selected automatically.

examples/quiver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ int main()
66
{
77
// u and v are respectively the x and y components of the arrows we're plotting
88
std::vector<int> x, y, u, v;
9-
for (int i = -5; i <= 5; i++) {
10-
for (int j = -5; j <= 5; j++) {
9+
10+
for (int i = -5; i <= 5; i++) for (int j = -5; j <= 5; j++)
11+
{
1112
x.push_back(i);
1213
u.push_back(-i);
1314
y.push_back(j);
1415
v.push_back(-j);
1516
}
16-
}
1717

1818
plt::quiver(x, y, u, v);
1919
plt::show();

examples/xkcd.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#define _USE_MATH_DEFINES
2-
#include <cmath>
3-
#include "../matplotlibcpp.h"
42
#include <vector>
3+
#include <cml/math.h>
4+
#include "../matplotlibcpp.h"
55

66
namespace plt = matplotlibcpp;
77

8-
int main() {
8+
int main()
9+
{
910
std::vector<double> t(1000);
1011
std::vector<double> x(t.size());
1112

12-
for(size_t i = 0; i < t.size(); i++) {
13+
for (size_t i = 0; i < t.size(); i++)
14+
{
1315
t[i] = i / 100.0;
14-
x[i] = sin(2.0 * M_PI * 1.0 * t[i]);
16+
x[i] = cml_sin(2.0 * M_PI * 1.0 * t[i]);
1517
}
1618

1719
plt::xkcd();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

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