Skip to content

Commit ba9343f

Browse files
yuma-mBenno Evers
authored andcommitted
Add animation example
1 parent 63d0e15 commit ba9343f

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
examples: minimal basic modern
1+
examples: minimal basic modern animation
22

33
minimal: examples/minimal.cpp matplotlibcpp.h
44
cd examples && g++ -DWITHOUT_NUMPY minimal.cpp -I/usr/include/python2.7 -lpython2.7 -o minimal -std=c++11
@@ -9,3 +9,5 @@ basic: examples/basic.cpp matplotlibcpp.h
99
modern: examples/modern.cpp matplotlibcpp.h
1010
cd examples && g++ modern.cpp -I/usr/include/python2.7 -lpython2.7 -o modern -std=c++11
1111

12+
animation: examples/animation.cpp matplotlibcpp.h
13+
cd examples && g++ animation.cpp -I/usr/include/python2.7 -lpython2.7 -o animation -std=c++11

examples/animation.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#define _USE_MATH_DEFINES
2+
#include <cmath>
3+
#include "../matplotlibcpp.h"
4+
5+
namespace plt = matplotlibcpp;
6+
7+
int main()
8+
{
9+
int n = 1000;
10+
std::vector<double> x, y, z;
11+
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));
16+
17+
if (i % 10 == 0) {
18+
// Clear previous plot
19+
plt::clf();
20+
// Plot line from given x and y data. Color is selected automatically.
21+
plt::plot(x, y);
22+
// Plot a line whose name will show up as "log(x)" in the legend.
23+
plt::named_plot("log(x)", x, z);
24+
25+
// Set x-axis to interval [0,1000000]
26+
plt::xlim(0, n*n);
27+
28+
// Add graph title
29+
plt::title("Sample figure");
30+
// Enable legend.
31+
plt::legend();
32+
// Display plot continuously
33+
plt::pause(0.01);
34+
}
35+
}
36+
}

examples/animation.gif

32.5 KB
Loading

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