@@ -41,17 +41,18 @@ int main()
41
41
z.at(i) = log(i);
42
42
}
43
43
44
- // Set the size of output image = 1200x780 pixels
44
+ // Set the size of output image to 1200x780 pixels
45
45
plt::figure_size(1200, 780);
46
46
// Plot line from given x and y data. Color is selected automatically.
47
47
plt::plot(x, y);
48
48
// Plot a red dashed line from given x and y data.
49
49
plt::plot(x, w,"r--");
50
50
// Plot a line whose name will show up as "log(x)" in the legend.
51
51
plt::named_plot("log(x)", x, z);
52
-
53
52
// Set x-axis to interval [0,1000000]
54
53
plt::xlim(0, 1000*1000);
54
+ // Add graph title
55
+ plt::title("Sample figure");
55
56
// Enable legend.
56
57
plt::legend();
57
58
// Save the image (file format is determined by the extension)
@@ -60,7 +61,9 @@ int main()
60
61
```
61
62
g++ basic.cpp -I/usr/include/python2.7 -lpython2.7
62
63
63
- Result: ![ Basic example] ( ./examples/basic.png )
64
+ ** Result:**
65
+
66
+ ![ Basic example] ( ./examples/basic.png )
64
67
65
68
matplotlib-cpp doesn't require C++11, but will enable some additional syntactic sugar when available:
66
69
``` cpp
@@ -93,7 +96,9 @@ int main()
93
96
```
94
97
g++ modern.cpp -std=c++11 -I/usr/include/python2.7 -lpython
95
98
96
- Result: 
99
+ **Result:**
100
+
101
+ 
97
102
98
103
Or some *funny-looking xkcd-styled* example:
99
104
```cpp
@@ -123,7 +128,36 @@ int main() {
123
128
124
129
** Result:**
125
130
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
+ 
127
161
128
162
Installation
129
163
------------
0 commit comments