8000 Update README and Makefile for quiver plot example. · michLab/matplotlib-cpp@0791945 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0791945

Browse files
author
Benno Evers
committed
Update README and Makefile for quiver plot example.
1 parent c1ad253 commit 0791945

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
examples: minimal basic modern animation nonblock xkcd
1+
examples: minimal basic modern animation nonblock xkcd quiver
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
@@ -15,8 +15,11 @@ animation: examples/animation.cpp matplotlibcpp.h
1515
nonblock: examples/nonblock.cpp matplotlibcpp.h
1616
cd examples && g++ nonblock.cpp -I/usr/include/python2.7 -lpython2.7 -o nonblock -std=c++11
1717

18+
quiver: examples/quiver.cpp matplotlibcpp.h
19+
cd examples && g++ quiver.cpp -I/usr/include/python2.7 -lpython2.7 -o quiver -std=c++11
20+
1821
xkcd: examples/xkcd.cpp matplotlibcpp.h
1922
cd examples && g++ xkcd.cpp -I/usr/include/python2.7 -lpython2.7 -o xkcd -std=c++11
2023

2124
clean:
22-
rm -f examples/{minimal,basic,modern,animation,nonblock,xkcd}
25+
rm -f examples/{minimal,basic,modern,animation,nonblock,xkcd,quiver}

README.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,18 @@ int main()
4141
z.at(i) = log(i);
4242
}
4343
44-
// Set the size of output image = 1200x780 pixels
44+
// Set the size of output image to 1200x780 pixels
4545
plt::figure_size(1200, 780);
4646
// Plot line from given x and y data. Color is selected automatically.
4747
plt::plot(x, y);
4848
// Plot a red dashed line from given x and y data.
4949
plt::plot(x, w,"r--");
5050
// Plot a line whose name will show up as "log(x)" in the legend.
5151
plt::named_plot("log(x)", x, z);
52-
5352
// Set x-axis to interval [0,1000000]
5453
plt::xlim(0, 1000*1000);
54+
// Add graph title
55+
plt::title("Sample figure");
5556
// Enable legend.
5657
plt::legend();
5758
// Save the image (file format is determined by the extension)
@@ -60,7 +61,9 @@ int main()
6061
```
6162
g++ basic.cpp -I/usr/include/python2.7 -lpython2.7
6263

63-
Result: ![Basic example](./examples/basic.png)
64+
**Result:**
65+
66+
![Basic example](./examples/basic.png)
6467

6568
matplotlib-cpp doesn't require C++11, but will enable some additional syntactic sugar when available:
6669
```cpp
@@ -93,7 +96,9 @@ int main()
9396
```
9497
g++ modern.cpp -std=c++11 -I/usr/include/python2.7 -lpython
9598
96-
Result: ![Modern example](./examples/modern.png)
99+
**Result:**
100+
101+
![Modern example](./examples/modern.png)
97102
98103
Or some *funny-looking xkcd-styled* example:
99104
```cpp
@@ -123,7 +128,36 @@ int main() {
123128

124129
**Result:**
125130

126-
![Minimal example](./examples/xkcd.png)
131+
![xkcd example](./examples/xkcd.png)
132+
133+
When working with vector fields, you might be interested in quiver plots:
134+
```cpp
135+
#include "../matplotlibcpp.h"
136+
137+
namespace plt = matplotlibcpp;
138+
139+
int main()
140+
{
141+
// u and v are respectively the x and y components of the arrows we're plotting
142+
std::vector<int> x, y, u, v;
143+
for (int i = -5; i <= 5; i++) {
144+
for (int j = -5; j <= 5; j++) {
145+
x.push_back(i);
146+
u.push_back(-i);
147+
y.push_back(j);
148+
v.push_back(-j);
149+
}
150+
}
151+
152+
plt::quiver(x, y, u, v);
153+
plt::show();
154+
}
155+
```
156+
g++ quiver.cpp -std=c++11 -I/usr/include/python2.7 -lpython2.7
157+
158+
**Result:**
159+
160+
![quiver example](./examples/quiver.png)
127161
128162
Installation
129163
------------

0 commit comments

Comments
 (0)
0