- 3.0.2 core module.
plot.h
Go to the documentation of this file.
1 // Derived from :
2 //
3 // Copyright (c) 2015-2016, ETH Zurich, Wyss Zurich, Zurich Eye
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of the ETH Zurich, Wyss Zurich, Zurich Eye nor the
14 // names of its contributors may be used to endorse or promote products
15 // derived from this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND
19 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL ETH Zurich, Wyss Zurich, Zurich Eye BE LIABLE
22 // FOR ANY
23 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Derived from work of Benno Evers licensed:
31 //
32 // The MIT License (MIT)
33 //
34 // Copyright (c) 2014 Benno Evers
35 //
36 // Permission is hereby granted, free of charge, to any person obtaining a copy
37 // of this software and associated documentation files (the "Software"), to deal
38 // in the Software without restriction, including without limitation the rights
39 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
40 // copies of the Software, and to permit persons to whom the Software is
41 // furnished to do so, subject to the following conditions:
42 //
43 // The above copyright notice and this permission notice shall be included in
44 // all
45 // copies or substantial portions of the Software.
46 //
47 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
48 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
49 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
50 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
51 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
52 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
53 // SOFTWARE.
54 
55 #pragma once
56 
57 #include <vector>
58 #include <map>
59 #include <numeric>
60 #include <stdexcept>
61 #include <iostream>
62 #include <initializer_list>
63 #include <Eigen/Dense>
64 #include <Eigen/StdVector>
65 
66 namespace ct {
67 namespace core {
68 namespace plot {
69 
70 
72 bool ion();
73 
75 bool figure(std::string i = "");
76 
78 bool hist(const Eigen::Ref<const Eigen::VectorXd>& x, const double bins = 10, const std::string histtype = "bar");
79 
81 bool boxplot(const Eigen::Ref<const Eigen::MatrixXd>& x, const std::vector<std::string>& labels);
82 bool boxplot(const Eigen::Ref<const Eigen::MatrixXd>& x, std::initializer_list<const std::string> labels);
83 bool boxplot(const Eigen::Ref<const Eigen::MatrixXd>& x);
84 
86 bool subplot(const size_t nrows, const size_t ncols, const size_t plot_number);
87 
89 bool plot(const Eigen::Ref<const Eigen::MatrixXd>& x,
90  const Eigen::Ref<const Eigen::MatrixXd>& y,
91  const std::map<std::string, std::string>& keywords);
92 
94 bool plot(const Eigen::Ref<const Eigen::MatrixXd>& x,
95  const Eigen::Ref<const Eigen::MatrixXd>& y,
96  const std::string& s = "");
97 
99 bool labelPlot(const std::string& name,
100  const Eigen::Ref<const Eigen::MatrixXd>& x,
101  const Eigen::Ref<const Eigen::MatrixXd>& y,
102  const std::string& format = "");
103 bool labelPlot(const std::string& name, const Eigen::Ref<const Eigen::MatrixXd>& y, const std::string& format = "");
104 
105 bool plot(const Eigen::Ref<const Eigen::MatrixXd>& x, const std::string& format = "");
106 
107 // -----------------------------------------------------------------------------
110 
111 template <typename ALLOC>
112 bool plot(const std::vector<double, ALLOC>& y, const std::string& format = "");
113 
114 template <typename ALLOC, typename ALLOC2>
115 bool plot(const std::vector<double, ALLOC>& x,
116  const std::vector<double, ALLOC2>& y,
117  const std::map<std::string, std::string>& keywords);
118 
119 bool plot(const std::vector<double>& x,
120  const Eigen::Ref<const Eigen::MatrixXd>& y,
121  const std::map<std::string, std::string>& keywords);
122 
123 template <typename ALLOC, typename ALLOC2>
124 bool plot(const std::vector<double, ALLOC>& x, const std::vector<double, ALLOC2>& y, const std::string& s = "");
125 
126 bool plot(const std::vector<double>& x, const Eigen::Ref<const Eigen::MatrixXd>& y, const std::string& s = "");
127 
128 bool labelPlot(const std::string& name,
129  const std::vector<double>& x,
130  const std::vector<double>& y,
131  const std::string& format = "");
132 
133 bool labelPlot(const std::string& name,
134  const std::vector<double>& x,
135  const Eigen::Ref<const Eigen::MatrixXd>& y,
136  const std::string& format = "");
138 
139 // -----------------------------------------------------------------------------
142 void legend();
143 
144 void ylim(double min, double max);
145 
146 void xlim(double xmin, double xmax);
147 
148 void title(const std::string& titlestr);
149 
150 void axis(const std::string& axisstr);
151 
152 void xlabel(const std::string& str);
153 
154 void ylabel(const std::string& str);
155 
156 void grid(bool flag);
157 
158 void show(bool block = true);
159 
160 void save(const std::string& filename);
162 
163 void warn();
164 
165 #include "plot-impl.h"
166 }
167 }
168 }
void ylim(double min, double max)
Definition: plot.cpp:871
void grid(bool flag)
Definition: plot.cpp:907
void xlabel(const std::string &str)
Definition: plot.cpp:895
bool ion()
Enable interactive mode.
Definition: plot.cpp:736
void ylabel(const std::string &str)
Definition: plot.cpp:901
void xlim(double xmin, double xmax)
Definition: plot.cpp:877
bool plot(const Eigen::Ref< const Eigen::MatrixXd > &x, const Eigen::Ref< const Eigen::MatrixXd > &y, const std::map< std::string, std::string > &keywords)
Create an x/y plot with properties as map.
Definition: plot.cpp:786
void axis(const std::string &axisstr)
Definition: plot.cpp:889
bool boxplot(const Eigen::Ref< const Eigen::MatrixXd > &x, const std::vector< std::string > &labels)
Every row of X is the data for a box.
Definition: plot.cpp:758
for i
void show(bool block=true)
Definition: plot.cpp:913
bool hist(const Eigen::Ref< const Eigen::VectorXd > &x, const double bins=10, const std::string histtype="bar")
Histogram.
Definition: plot.cpp:751
ct::core::StateVector< state_dim > x
bool plot(const std::vector< double > &x, const Eigen::Ref< const Eigen::MatrixXd > &y, const std::string &s="")
Definition: plot.cpp:838
void title(const std::string &titlestr)
Definition: plot.cpp:883
bool labelPlot(const std::string &name, const Eigen::Ref< const Eigen::MatrixXd > &x, const Eigen::Ref< const Eigen::MatrixXd > &y, const std::string &format="")
Create an x/y plot with name as label.
Definition: plot.cpp:804
void warn()
Definition: plot.cpp:730
void legend()
Definition: plot.cpp:865
bool subplot(const size_t nrows, const size_t ncols, const size_t plot_number)
Create a subplot.
Definition: plot.cpp:779
void save(const std::string &filename)
Definition: plot.cpp:919
bool figure(std::string i="")
Create a new figure.
Definition: plot.cpp:744