├── package.xml
├── CMakeLists.txt
├── README.md
├── LICENSE
├── src
├── mpl_example_node.cpp
└── matplotlibcpp.cpp
└── include
└── plotty
└── matplotlibcpp.hpp
/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | plotty
4 | 0.1.4
5 | The plotty package.
6 | Copied from https://github.com/zurich-eye/ze_oss/tree/master/ze_matplotlib
7 | and removed all the dependencies.
8 |
9 |
10 | Michael Burri
11 | BSD
12 |
13 | catkin
14 | catkin_simple
15 |
16 | eigen_catkin
17 | glog_catkin
18 |
19 | gtest
20 |
21 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 2.8.3)
2 | project(plotty)
3 |
4 | find_package(catkin_simple REQUIRED)
5 | catkin_simple(ALL_DEPS_REQUIRED)
6 |
7 | add_definitions(-std=c++11 -Wno-sign-compare -Wno-unused-value)
8 |
9 | # The matplotlib-cpp headers are linked against
10 | find_package(PythonLibs)
11 | include_directories(${PYTHON_INCLUDE_DIRS})
12 |
13 | add_definitions(-DPYTHON_VERSION_MAJOR=${PYTHON_VERSION_MAJOR})
14 |
15 | #############
16 | # LIBRARIES #
17 | #############
18 | set(HEADERS
19 | include/plotty/matplotlibcpp.hpp
20 | )
21 |
22 | set(SOURCES
23 | src/matplotlibcpp.cpp
24 | )
25 |
26 | cs_add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS})
27 | target_link_libraries(${PROJECT_NAME} ${PYTHON_LIBRARY})
28 |
29 | ###############
30 | # EXECUTABLES #
31 | ###############
32 |
33 | cs_add_executable(mpl_example_node src/mpl_example_node.cpp)
34 | target_link_libraries(mpl_example_node ${PROJECT_NAME})
35 |
36 | ##########
37 | # EXPORT #
38 | ##########
39 | cs_install()
40 | cs_export()
41 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Plotty: C++ Interface to Matplotlib
2 | 
3 |
4 | ## Principles
5 |
6 | - `plotty::plot(...)` automatically creates a new figure
7 | - `plotty::show()` shows the results of the plot
8 | - calls to `plotty::plot(...)` go to the same plot until `plotty::show()` is called
9 | - by default, calls to `plotty::show()` are blocking and execution continues only after the plot window is closed
10 |
11 | ## Simple plot of a vector:
12 | ```c++
13 | // Std Vector:
14 | std::vector v({1, 2, 3, 4});
15 | plotty::plot(v);
16 | plotty::show();
17 |
18 | // Eigen Types:
19 | Eigen::VectorXd w(100);
20 | w.setRandom();
21 | plotty::plot(w)
22 | plotty::show();
23 | ```
24 |
25 | ## Plot x and y
26 | ```c++
27 | Eigen::VectorXd t(100);
28 | t.setLinSpaced(100, 0, 20);
29 | Eigen::VectorXd v(100);
30 | v.setRandom();
31 | plotty::plot(t, v);
32 | plotty::show();
33 | ```
34 |
35 | ## Subplots
36 | ```c++
37 | plotty::subplot(3, 1, 1);
38 | plotty::plot(v1);
39 | plotty::subplot(3, 1, 2);
40 | plotty::plot(v2);
41 | plotty::subplot(3, 1, 3);
42 | plotty::plot(v2);
43 | plotty::plot();
44 | ```
45 |
46 | ## Histogram
47 |
48 | The histogram function only exposes the `bins`, `data` and `type` parameters of matplotlibs histogram function.
49 | ```c++
50 | plotty::hist(v, 10, "bar");
51 | plotty::show();
52 | ```
53 |
54 | ## Formatting
55 |
56 | All functions accept optional format arguments (`plotty::plot(x, y, format)` or `plotty::plot(y, format)`). The
57 | expected format strings are equivalent to the matplotlib format strings:
58 | ```c++
59 | plotty::plot(t, v, "rx"); // red x'es
60 | plotty::show();
61 | ```
62 |
63 | ## Multiple open Plots
64 |
65 | `plotty::show(false)` opens a non-blocking window. You have to open a new figure to get a second plot ( `plotty::figure()`).
66 | The final figure should be opened in blocking mode to keep all windows open.
67 |
68 | ```c++
69 | plotty::plot(v1);
70 | plotty::show(false); // show non-blocking
71 |
72 | ...
73 |
74 | plotty::figure(); // new figure
75 | plotty::plot(v2)
76 | plotty::show(false); // open non-blocking
77 |
78 | ...
79 |
80 | plotty::figure();
81 | plotty::plot(v3);
82 | plotty::show(); // blocking to keep figures 1-3 open.
83 |
84 |
85 | ```
86 |
87 | `plotty::figure()` accepts a string argument that labels / identifies a specific plot.
88 |
89 | ## Style and Labels
90 |
91 | ```c++
92 | plotty::plot(t, x);
93 | plotty::xlabel("time [s]");
94 | plotty::ylabel("Position [m]");
95 | plotty::title("Position over time");
96 | plotty::xlim(t_start, t_end);
97 | plotty::ylim(0, x_max);
98 | ```
99 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2015-2016, ETH Zurich, Wyss Zurich, Zurich Eye
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 | * Redistributions of source code must retain the above copyright
7 | notice, this list of conditions and the following disclaimer.
8 | * Redistributions in binary form must reproduce the above copyright
9 | notice, this list of conditions and the following disclaimer in the
10 | documentation and/or other materials provided with the distribution.
11 | * Neither the name of the ETH Zurich, Wyss Zurich, Zurich Eye nor the
12 | names of its contributors may be used to endorse or promote products
13 | derived from this software without specific prior written permission.
14 |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 | DISCLAIMED. IN NO EVENT SHALL ETH Zurich, Wyss Zurich, Zurich Eye BE LIABLE FOR ANY
19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 |
26 | Derived from work of Benno Evers licensed:
27 |
28 | The MIT License (MIT)
29 |
30 | Copyright (c) 2014 Benno Evers
31 |
32 | Permission is hereby granted, free of charge, to any person obtaining a copy
33 | of this software and associated documentation files (the "Software"), to deal
34 | in the Software without restriction, including without limitation the rights
35 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
36 | copies of the Software, and to permit persons to whom the Software is
37 | furnished to do so, subject to the following conditions:
38 |
39 | The above copyright notice and this permission notice shall be included in all
40 | copies or substantial portions of the Software.
41 |
42 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
44 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
45 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
46 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
47 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
48 | SOFTWARE.
--------------------------------------------------------------------------------
/src/mpl_example_node.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015-2016, ETH Zurich, Wyss Zurich, Zurich Eye
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | // * Redistributions in binary form must reproduce the above copyright
9 | // notice, this list of conditions and the following disclaimer in the
10 | // documentation and/or other materials provided with the distribution.
11 | // * Neither the name of the ETH Zurich, Wyss Zurich, Zurich Eye nor the
12 | // names of its contributors may be used to endorse or promote products
13 | // derived from this software without specific prior written permission.
14 | //
15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 | // AND
17 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | // DISCLAIMED. IN NO EVENT SHALL ETH Zurich, Wyss Zurich, Zurich Eye BE LIABLE
20 | // FOR ANY
21 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 |
28 | #include
29 |
30 | int main() {
31 | // Simple:
32 | std::vector v({1, 2, 3, 4});
33 | plotty::plot(v);
34 | plotty::show();
35 |
36 | // Eigen Vector Types:
37 | Eigen::VectorXd times(100);
38 | times.setLinSpaced(100, 0, 20);
39 | Eigen::VectorXd points(100);
40 | points.setRandom();
41 |
42 | plotty::plot(times, points);
43 | plotty::show();
44 |
45 | plotty::labelPlot("A Name", times, points);
46 | plotty::show();
47 |
48 | // enable interactive mode as of now (only tests if it doesn't crash)
49 | plotty::ion();
50 |
51 | // subplots
52 | plotty::subplot(3, 1, 1);
53 | plotty::plot(v);
54 | plotty::subplot(3, 1, 2);
55 | plotty::plot(v);
56 | plotty::subplot(3, 1, 3);
57 | plotty::plot(v);
58 | plotty::show(false);
59 |
60 | plotty::figure();
61 |
62 | // plot multiple curves in a single graph
63 | std::vector w({4, 3, 2, 1});
64 | plotty::plot(v, "x");
65 | plotty::plot(w, "o");
66 | plotty::show();
67 |
68 | // Histogram
69 | plotty::hist(points, 3);
70 | plotty::show();
71 |
72 | // Row vectors
73 | Eigen::MatrixXd matrix(2, 100);
74 | matrix.setRandom();
75 | plotty::plot(matrix.row(0), matrix.row(1));
76 | plotty::show();
77 |
78 | // BoxPlot
79 | Eigen::MatrixXd data(2, 100);
80 | data.setRandom();
81 | plotty::figure();
82 | std::vector labels = {"A", "B"};
83 | plotty::boxplot(data, labels);
84 | plotty::show();
85 |
86 | // BoxPlot
87 | data.setRandom();
88 | plotty::figure();
89 | plotty::boxplot(data, {"A", "B"});
90 | plotty::show();
91 |
92 | // Boxplot unlabelled
93 | data.setRandom();
94 | plotty::figure();
95 | plotty::boxplot(data);
96 | plotty::show();
97 | }
98 |
--------------------------------------------------------------------------------
/include/plotty/matplotlibcpp.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015-2016, ETH Zurich, Wyss Zurich, Zurich Eye
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are met:
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | // * Redistributions in binary form must reproduce the above copyright
9 | // notice, this list of conditions and the following disclaimer in the
10 | // documentation and/or other materials provided with the distribution.
11 | // * Neither the name of the ETH Zurich, Wyss Zurich, Zurich Eye nor the
12 | // names of its contributors may be used to endorse or promote products
13 | // derived from this software without specific prior written permission.
14 | //
15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 | // AND
17 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | // DISCLAIMED. IN NO EVENT SHALL ETH Zurich, Wyss Zurich, Zurich Eye BE LIABLE
20 | // FOR ANY
21 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | //
28 | // Derived from work of Benno Evers licensed:
29 | //
30 | // The MIT License (MIT)
31 | //
32 | // Copyright (c) 2014 Benno Evers
33 | //
34 | // Permission is hereby granted, free of charge, to any person obtaining a copy
35 | // of this software and associated documentation files (the "Software"), to deal
36 | // in the Software without restriction, including without limitation the rights
37 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
38 | // copies of the Software, and to permit persons to whom the Software is
39 | // furnished to do so, subject to the following conditions:
40 | //
41 | // The above copyright notice and this permission notice shall be included in
42 | // all
43 | // copies or substantial portions of the Software.
44 | //
45 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
48 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
50 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
51 | // SOFTWARE.
52 |
53 | #pragma once
54 |
55 | #include
56 | #include