8000 update docs · intercore/matplotlib-cpp@520f91e · GitHub
[go: up one dir, main page]

Skip to content

Commit 520f91e

Browse files
committed
update docs
1 parent 0acff6b commit 520f91e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2369
-594
lines changed

docs/build/doctrees/docs.doctree

-4.53 KB
Binary file not shown.
15.7 KB
Binary file not shown.

docs/build/doctrees/example.doctree

8.36 KB
Binary file not shown.

docs/build/doctrees/examples.doctree

8.31 KB
Binary file not shown.

docs/build/doctrees/index.doctree

281 Bytes
Binary file not shown.

docs/build/doctrees/problems.doctree

7.39 KB
Binary file not shown.

docs/build/doctrees/style.doctree

41.1 KB
Binary file not shown.
2.77 KB
Loading
129 KB
Loading
12.2 KB
Binary file not shown.
12.2 KB
Binary file not shown.

docs/build/html/_images/eigen.pdf

11.5 KB
Binary file not shown.

docs/build/html/_images/minimal.pdf

5.37 KB
Binary file not shown.

docs/build/html/_images/standard.pdf

12 KB
Binary file not shown.
9.72 KB
Loading

docs/build/html/_sources/docs.rst.txt

Lines changed: 31 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -3,116 +3,31 @@
33
The Docs
44
********
55

6-
.. _STL vector: https://en.cppreference.com/w/cpp/container/vector
7-
6+
`matplotlibcpp` namespace
7+
=========================
88

9-
.. _style:
109

11-
The style of a line
12-
===================
10+
All functions are organised in the namespace `matplotlibcpp`.
11+
For convenience (and in spirit of the Python norm) we usually
12+
define the abbreviation `plt`:
1313

14-
The style of a line in a plot has three characteristics; the
15-
marker, the color and the line.
16-
They can be specified using the keywords map
17-
or the formatting string.
18-
19-
They keywords map is a possibility to specify additional parameters
20-
for the plot commands. To set the line style it can be used as follows.
2114
.. code-block:: cpp
2215
23-
// for a red dashed line with circle markers
24-
plt::plot(x, y, {{"color", "red"}, {"marker": "o"}, {"linestyle": "--"}})
25-
26-
// shorthand notation for color and linestyle is usually supported
27-
plt::plot(x, y, {{"c", "red"}, {"marker": "o"}, {"ls": "--"}})
28-
29-
See sections `Marker`_, `Color`_ and `Line`_
30-
for supported values.
31-
32-
The formatting string is a convenient notation to set the style of a line.
33-
Almost all plot commands support the formatting string as
34-
first argument after the `x` and `y` data.
35-
36-
A formatting string's structure is
37-
```
38-
s = "<marker><color><line>"
39-
```
16+
#include "matplotlibcpp.h"
17+
namespace plt = matplotlibcpp;
4018
41-
The rules are
42-
43-
x. The valid parameters (``<>``) are listed in the following sections.
44-
45-
x. Different ordering of the parameters is supported.
46-
However, to avoid ambiguity this order should be used throughout.
47-
48-
x. Parameters might be dropped.
49-
50-
x. If only the colour parameters is specified, more color
51-
parameters are supported, see section `Color`_.
52-
53-
**Examples**
19+
The function can then be accessed via:
5420

5521
.. code-block:: cpp
5622
57-
"b" // blue line
58-
"og" // green circles, no connecting line
59-
"og-" // green circles with connecting line
60-
"r--" // dashed red line
61-
"seagreen" // a solid line in the colour seagreen
62-
"#008000" // a solid line coloured in the HEX code
63-
64-
The following sections list the supported markers, colours and linestyles.
65-
66-
Marker
67-
++++++
23+
matplotlibcpp::plot(x, y);
24+
plt::loglog(x, y); // if we defined namespace plt = matplotlibcpp
6825
69-
========= ======
70-
character marker
71-
========= ======
72-
'o' circle
73-
========= ======
7426
75-
Color
76-
+++++
77-
78-
The color can be specified via a character code,
79-
a full name or a HEX code.
80-
81-
.. note::
82-
83-
If a formatting string contains more parameters than just the color,
84-
only the character code is supported.
85-
86-
Character code
87-
^^^^^^^^^^^^^^
88-
89-
========= ======
90-
character color
91-
========= ======
92-
'r' red
93-
========= ======
94-
95-
Full name
96-
^^^^^^^^^
97-
98-
E.g. seagreen
99-
100-
HEX code
101-
^^^^^^^^
102-
103-
Just use HEX
104-
105-
Line
106-
++++
107-
108-
========= ======
109-
character line
110-
========= ======
111-
'-' solid
112-
========= ======
27+
`Vector` type
28+
=============
11329

114-
The `Vector` type
115-
=================
30+
.. _STL vector: https://en.cppreference.com/w/cpp/container/vector
11631

11732
.. cpp:type:: Vector
11833

@@ -157,14 +72,16 @@ The `Vector` type
15772
Plot commands
15873
=============
15974

75+
.. cpp:namespace:: matplotlibcpp
76+
16077
.. _mpl_plot: https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.plot.html
16178

16279
.. cpp:function::
16380
template <typename VectorX, typename VectorY> \
16481
bool plot(const VectorX &x, const VectorY &y, const std::string &s = "", \
16582
const std::map<std::string, std::string> &keywords = {})
16683

167-
.. image:: ../matplotlib_icon.png
84+
.. image:: ../img/matplotlib_icon.png
16885
:align: right
16986
:width: 20px
17087
:height: 20px
@@ -231,7 +148,7 @@ Plot commands
231148
bool plot(const VectorY &y, const std::string &format = "", \
232149
const std::map<std::string, std::string> &keywords = {})
233150

234-
.. image:: ../matplotlib_icon.png
151+
.. image:: ../img/matplotlib_icon.png
235152
:align: right
236153
:width: 20px
237154
:height: 20px
@@ -281,7 +198,7 @@ Plot commands
281198
bool loglog(const VectorX &x, const VectorY &y, const std::string &s = "", \
282199
const std::map<std::string, std::string> &keywords = {})
283200

284-
.. image:: ../matplotlib_icon.png
201+
.. image:: ../img/matplotlib_icon.png
285202
:align: right
286203
:width: 20px
287204
:height: 20px
@@ -326,7 +243,7 @@ Plot commands
326243
bool loglog(const VectorY &y, const std::string &s = "", \
327244
const std::map<std::string, std::string> &keywords = {})
328245

329-
.. image:: ../matplotlib_icon.png
246+
.. image:: ../img/matplotlib_icon.png
330247
:align: right
331248
:width: 20px
332249
:height: 20px
@@ -365,7 +282,7 @@ Plot commands
365282
bool semilogx(const VectorX &x, const VectorY &y, const std::string &s = "", \
366283
const std::map<std::string, std::string> &keywords = {})
367284

368-
.. image:: ../matplotlib_icon.png
285+
.. image:: ../img/matplotlib_icon.png
369286
:align: right
370287
:width: 20px
371288
:height: 20px
@@ -384,7 +301,7 @@ Plot commands
384301
bool semilogx(const VectorY &y, const std::string &s = "", \
385302
const std::map<std::string, std::string> &keywords = {})
386303

387-
.. image:: ../matplotlib_icon.png
304+
.. image:: ../img/matplotlib_icon.png
388305
:align: right
389306
:width: 20px
390307
:height: 20px
@@ -406,7 +323,7 @@ Plot commands
406323
bool semilogy(const VectorX &x, const VectorY &y, const std::string &s = "", \
407324
const std::map<std::string, std::string> &keywords = {})
408325

409-
.. image:: ../matplotlib_icon.png
326+
.. image:: ../img/matplotlib_icon.png
410327
:align: right
411328
:width: 20px
412329
:height: 20px
@@ -425,7 +342,7 @@ Plot commands
425342
bool semilogy(const VectorY &y, const std::string &s = "", \
426343
const std::map<std::string, std::string> &keywords = {})
427344

428-
.. image:: ../matplotlib_icon.png
345+
.. image:: ../img/matplotlib_icon.png
429346
:align: right
430347
:width: 20px
431348
:height: 20px
@@ -445,7 +362,7 @@ Plot commands
445362
template <typename Numeric> \
446363
void text(Numeric x, Numeric y, const std::string &s = "")
447364

448-
.. image:: ../matplotlib_icon.png
365+
.. image:: ../img/matplotlib_icon.png
449366
:align: right
450367
:width: 20px
451368
:height: 20px
@@ -487,7 +404,7 @@ Figure commands
487404
.. cpp:function::
488405
inline long figure(long number = -1)
489406

490-
.. image:: ../matplotlib_icon.png
407+
.. image:: ../img/matplotlib_icon.png
491408
:align: right
492409
:width: 20px
493410
:height: 20px
@@ -523,7 +440,7 @@ Figure commands
523440
inline void legend(const std::string &loc = "best", \
524441
const Vector &bbox_to_anchor = Vector())
525442

526-
.. image:: ../matplotlib_icon.png
443+
.. image:: ../img/matplotlib_icon.png
527444
:align: right
528445
:width: 20px
529446
:height: 20px
@@ -556,7 +473,7 @@ Figure commands
556473
template <typename Numeric> \
557474
void xlim(Numeric left, Numeric right)
558475

559-
.. image:: ../matplotlib_icon.png
476+
.. image:: ../img/matplotlib_icon.png
560477
:align: right
561478
:width: 20px
562479
:height: 20px
@@ -574,7 +491,7 @@ Figure commands
574491
template <typename Numeric> \
575492
void ylim(Numeric bottom, Numeric top)
576493

577-
.. image:: ../matplotlib_icon.png
494+
.. image:: ../img/matplotlib_icon.png
578495
:align: right
579496
:width: 20px
580497
:height: 20px
@@ -608,7 +525,7 @@ Figure commands
608525
inline void title(const std::string &titlestr, \
609526
const std::map<std::string, std::string> &keywords = {})
610527

611-
.. image:: ../matplotlib_icon.png
528+
.. image:: ../img/matplotlib_icon.png
612529
:align: right
613530
:width: 20px
614531
:height: 20px
@@ -626,7 +543,7 @@ Figure commands
626543
inline void suptitle(const std::string &suptitlestr, \
627544
const std::map<std::string, std::string> &keywords = {})
628545

629-
.. image:: ../matplotlib_icon.png
546+
.. image:: ../img/matplotlib_icon.png
630547
:align: right
631548
:width: 20px
632549
:height: 20px
@@ -642,7 +559,7 @@ Figure commands
642559
.. cpp:function::
643560
inline void axis(const std::string &option)
644561

645-
.. image:: ../matplotlib_icon.png
562+
.. image:: ../img/matplotlib_icon.png
646563
:align: right
647564
:width: 20px
648565
:height: 20px
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
.. _example:
2+
3+
First examples
4+
**************
5+
6+
Minimal working example
7+
=======================
8+
9+
.. code-block:: cpp
10+
11+
#include "matplotlibcpp.h"
12+
#include <vector>
13+
14+
namespace plt = matplotlibcpp;
15+
16+
int main() {
17+
std::vector<double> y = {1, 3, 2, 4};
18+
plt::plot(y);
19+
plt::savefig("minimal.pdf");
20+
}
21+
22+
produces the output
23+
24+
.. image:: ../img/examples/minimal.pdf
25+
26+
Standard usage
27+
==============
28+
29+
.. code-block:: cpp
30+
31+
#define _USE_MATH_DEFINES // for sin/log
32+
#include "../matplotlibcpp.h"
33+
#include <cmath>
34+
#include <iostream>
35+
36+
namespace plt = matplotlibcpp;
37+
38+
int main() {
39+
int n = 5000; // 5000 data points
40+
std::vector<double> x(n), y(n), z(n), w(n, 2);
41+
for (int i = 0; i < n; ++i) {
42+
x.at(i) = i * i;
43+
y.at(i) = sin(2 * M_PI * i / 360.0);
44+
z.at(i) = log(i);
45+
}
46+
47+
plt::figure(); // declare a new figure (optional if only one is used)
48+
49+
plt::plot(x, y); // automatic coloring: tab:blue
50+
plt::plot(x, w, "r--"); // red dashed line
51+
plt::plot(x, z, {{"label", "log(x)"}}); // legend label "log(x)"
52+
53+
plt::xlim(0, 1000 * 1000); // x-axis interval: [0, 1e6]
54+
plt::title("Standard usage"); // set a title
55+
plt::legend(); // enable the legend
56+
57+
plt::savefig("standard.pdf"); // save the figure
58+
}
59+
60+
produces the output
61+
62+
.. image:: ../img/examples/standard.pdf
63+
64+
Eigen vectors
65+
=============
66+
67+
.. code-block:: cpp
68+
69+
#include "../../matplotlibcpp.h"
70+
#include <Eigen/Dense>
71+
#include <iostream>
72+
73+
namespace plt = matplotlibcpp;
74+
75+
int main() {
76+
77+
Eigen::VectorXd x = Eigen::VectorXd::LinSpaced(200, 0, 6);
78+
Eigen::VectorXd y, z;
79+
80+
// y = exp(sin(x)), z = exp(cos(z))
81+
y = x.array().sin().exp().matrix();
82+
z = x.array().cos().exp().matrix();
83+
84+
plt::figure();
85+
86+
plt::semilogx(x, y, "tab:red");
87+
plt::semilogx(x, z, "tab:blue", {{"linestyle", "--"}});
88+
89+
plt::xlabel("Time in lecture");
90+
plt::ylabel("Student confusion");
91+
92+
plt::grid();
93+
plt::savefig("eigen.pdf");
94+
plt::show(); // show the figure instead of saving it
95+
}
96+
97+
produces the output
98+
99+
.. image:: ../img/examples/eigen.pdf

0 commit comments

Comments
 (0)
0