34 #include <sciplot/Plot2D.hpp>
35 #include <sciplot/Plot3D.hpp>
36 #include <sciplot/specs/FontSpecsOf.hpp>
37 #include <sciplot/specs/LayoutSpecs.hpp>
43 using PlotVariant = std::variant<Plot2D, Plot3D>;
45 template <
typename... Ts>
48 using Ts::operator()...;
50 template <
class... Ts>
53 static constexpr
auto SavePlotVisitor =
Overload{
55 { p.savePlotData(); },
57 { p.savePlotData(); }};
59 static constexpr
auto ReprPlotVisitor = Overload{
63 {
return p.repr(); }};
65 static constexpr
auto CleanupPlotVisitor = Overload{
76 Figure(
const std::initializer_list<std::initializer_list<PlotVariant>>& plots);
79 Figure(
const std::vector<std::vector<PlotVariant>>& plots);
113 auto
repr() const -> std::
string;
117 static std::
size_t m_counter;
121 std::
size_t m_id = 0;
127 std::
size_t m_layoutrows = 0;
129 std::
size_t m_layoutcols = 0;
135 std::vector<std::vector<PlotVariant>> m_plots;
139 inline std::
size_t Figure::m_counter = 0;
141 inline
Figure::
Figure(const std::initializer_list<std::initializer_list<PlotVariant>>& plots)
144 m_layoutrows = plots.size();
146 for (
const auto& row : plots)
147 m_layoutcols = std::max<decltype(m_layoutcols)>(m_layoutcols, row.size());
149 for (
const auto& row : plots)
150 m_plots.emplace_back(row.begin(), row.end());
154 : m_id(m_counter++), m_plots(plots)
156 m_layoutrows = plots.size();
158 for (
const auto& row : plots)
159 m_layoutcols = std::max<decltype(m_layoutcols)>(m_layoutcols, row.size());
164 auto& plot = m_plots.at(j).at(i);
165 if (std::holds_alternative<Plot2D>(plot))
167 return std::get<Plot2D>(plot);
169 else if (std::holds_alternative<Plot3D>(plot))
171 return std::get<Plot3D>(plot);
173 throw std::runtime_error(
"Unknown plot type / Empty variant");
179 return std::get<Plot2D>(m_plots.at(j).at(i));
185 return std::get<Plot3D>(m_plots.at(j).at(i));
190 for (
auto& row : m_plots)
192 for (
auto& plot : row)
194 if (std::holds_alternative<Plot2D>(plot))
196 std::get<Plot2D>(plot).
palette(name);
198 else if (std::holds_alternative<Plot3D>(plot))
200 std::get<Plot3D>(plot).palette(name);
220 std::stringstream script;
222 if (m_layoutrows > 1 || m_layoutcols > 1)
224 gnuplot::multiplotcmd(script, m_layoutrows, m_layoutcols, m_title);
226 script << m_layout << std::endl;
227 for (
const auto& row : m_plots)
229 for (
const auto& plot : row)
231 script << std::visit(ReprPlotVisitor, plot);
235 if (m_layoutrows > 1 || m_layoutcols > 1)
237 script <<
"unset multiplot" << std::endl;
244 for (
const auto& row : m_plots)
246 for (
const auto& plot : row)
248 std::visit(SavePlotVisitor, plot);
255 for (
const auto& row : m_plots)
257 for (
const auto& plot : row)
259 std::visit(CleanupPlotVisitor, plot);
Definition: Figure.hpp:47
The class used to create a plot containing graphical elements.
Definition: Plot.hpp:57
The class used to create a plot containing graphical elements.
Definition: Plot2D.hpp:58
The class used to specify layout options.
Definition: LayoutSpecs.hpp:87