9#include <matplotlibcpp17/axes.h>
10#include <matplotlibcpp17/common.h>
11#include <matplotlibcpp17/figure.h>
13#include <pybind11/embed.h>
14#include <pybind11/numpy.h>
15#include <pybind11/pybind11.h>
16#include <pybind11/stl.h>
18namespace matplotlibcpp17::pyplot {
26 PyPlot(pybind11::module mod_) {
31 axes::Axes axes(
const pybind11::dict &kwargs = pybind11::dict());
34 ObjectWrapper axis(
const pybind11::tuple &args = pybind11::tuple(),
35 const pybind11::dict &kwargs = pybind11::dict());
38 ObjectWrapper cla(
const pybind11::tuple &args = pybind11::tuple(),
39 const pybind11::dict &kwargs = pybind11::dict());
42 ObjectWrapper clf(
const pybind11::tuple &args = pybind11::tuple(),
43 const pybind11::dict &kwargs = pybind11::dict());
46 ObjectWrapper clim(
const pybind11::tuple &args = pybind11::tuple(),
47 const pybind11::dict &kwargs = pybind11::dict());
50 ObjectWrapper colorbar(
const pybind11::tuple &args = pybind11::tuple(),
51 const pybind11::dict &kwargs = pybind11::dict());
54 ObjectWrapper errorbar(
const pybind11::tuple &args = pybind11::tuple(),
55 const pybind11::dict &kwargs = pybind11::dict());
58 std::tuple<double, double>
59 figaspect(
const pybind11::tuple &args = pybind11::tuple(),
60 const pybind11::dict &kwargs = pybind11::dict());
63 figure::Figure figure(
const pybind11::tuple &args = pybind11::tuple(),
64 const pybind11::dict &kwargs = pybind11::dict());
67 axes::Axes gca(
const pybind11::tuple &args = pybind11::tuple(),
68 const pybind11::dict &kwargs = pybind11::dict());
71 figure::Figure gcf(
const pybind11::tuple &args = pybind11::tuple(),
72 const pybind11::dict &kwargs = pybind11::dict());
75 ObjectWrapper gci(
const pybind11::tuple &args = pybind11::tuple(),
76 const pybind11::dict &kwargs = pybind11::dict());
79 ObjectWrapper grid(
const pybind11::tuple &args = pybind11::tuple(),
80 const pybind11::dict &kwargs = pybind11::dict());
83 ObjectWrapper imshow(
const pybind11::tuple &args = pybind11::tuple(),
84 const pybind11::dict &kwargs = pybind11::dict());
87 ObjectWrapper legend(
const pybind11::tuple &args = pybind11::tuple(),
88 const pybind11::dict &kwargs = pybind11::dict());
91 ObjectWrapper pause(
const pybind11::tuple &args = pybind11::tuple(),
92 const pybind11::dict &kwargs = pybind11::dict());
95 ObjectWrapper plot(
const pybind11::tuple &args = pybind11::tuple(),
96 const pybind11::dict &kwargs = pybind11::dict());
99 ObjectWrapper quiver(
const pybind11::tuple &args = pybind11::tuple(),
100 const pybind11::dict &kwargs = pybind11::dict());
103 ObjectWrapper savefig(
const pybind11::tuple &args = pybind11::tuple(),
104 const pybind11::dict &kwargs = pybind11::dict());
107 ObjectWrapper scatter(
const pybind11::tuple &args = pybind11::tuple(),
108 const pybind11::dict &kwargs = pybind11::dict());
111 ObjectWrapper show(
const pybind11::tuple &args = pybind11::tuple(),
112 const pybind11::dict &kwargs = pybind11::dict());
115 ObjectWrapper step(
const pybind11::tuple &args = pybind11::tuple(),
116 const pybind11::dict &kwargs = pybind11::dict());
119 axes::Axes subplot(
const pybind11::dict &kwargs = pybind11::dict());
123 std::tuple<figure::Figure, axes::Axes>
124 subplots(
const pybind11::dict &kwargs = pybind11::dict());
125 std::tuple<figure::Figure, std::vector<axes::Axes>>
126 subplots(
int r,
int c,
const pybind11::dict &kwargs = pybind11::dict());
129 ObjectWrapper title(
const pybind11::tuple &args = pybind11::tuple(),
130 const pybind11::dict &kwargs = pybind11::dict());
133 ObjectWrapper xlabel(
const pybind11::tuple &args = pybind11::tuple(),
134 const pybind11::dict &kwargs = pybind11::dict());
137 ObjectWrapper xlim(
const pybind11::tuple &args = pybind11::tuple(),
138 const pybind11::dict &kwargs = pybind11::dict());
141 ObjectWrapper ylabel(
const pybind11::tuple &args = pybind11::tuple(),
142 const pybind11::dict &kwargs = pybind11::dict());
145 ObjectWrapper ylim(
const pybind11::tuple &args = pybind11::tuple(),
146 const pybind11::dict &kwargs = pybind11::dict());
150 LOAD_FUNC_ATTR(axes, mod);
151 LOAD_FUNC_ATTR(axis, mod);
152 LOAD_FUNC_ATTR(cla, mod);
153 LOAD_FUNC_ATTR(clf, mod);
154 LOAD_FUNC_ATTR(clim, mod);
155 LOAD_FUNC_ATTR(colorbar, mod);
156 LOAD_FUNC_ATTR(errorbar, mod);
157 LOAD_FUNC_ATTR(figaspect, mod);
158 LOAD_FUNC_ATTR(figure, mod);
159 LOAD_FUNC_ATTR(gca, mod);
160 LOAD_FUNC_ATTR(gcf, mod);
161 LOAD_FUNC_ATTR(gci, mod);
162 LOAD_FUNC_ATTR(grid, mod);
163 LOAD_FUNC_ATTR(imshow, mod);
164 LOAD_FUNC_ATTR(legend, mod);
165 LOAD_FUNC_ATTR(pause, mod);
166 LOAD_FUNC_ATTR(plot, mod);
167 LOAD_FUNC_ATTR(quiver, mod);
168 LOAD_FUNC_ATTR(savefig, mod);
169 LOAD_FUNC_ATTR(scatter, mod);
170 LOAD_FUNC_ATTR(show, mod);
171 LOAD_FUNC_ATTR(step, mod);
172 LOAD_FUNC_ATTR(subplot, mod);
173 LOAD_FUNC_ATTR(subplots, mod);
174 LOAD_FUNC_ATTR(title, mod);
175 LOAD_FUNC_ATTR(xlabel, mod);
176 LOAD_FUNC_ATTR(xlim, mod);
177 LOAD_FUNC_ATTR(ylabel, mod);
178 LOAD_FUNC_ATTR(ylim, mod);
180 pybind11::module mod;
181 pybind11::object axes_attr;
182 pybind11::object axis_attr;
183 pybind11::object cla_attr;
184 pybind11::object clf_attr;
185 pybind11::object clim_attr;
186 pybind11::object colorbar_attr;
187 pybind11::object errorbar_attr;
188 pybind11::object figaspect_attr;
189 pybind11::object figure_attr;
190 pybind11::object gca_attr;
191 pybind11::object gcf_attr;
192 pybind11::object gci_attr;
193 pybind11::object grid_attr;
194 pybind11::object imshow_attr;
195 pybind11::object legend_attr;
196 pybind11::object pause_attr;
197 pybind11::object plot_attr;
198 pybind11::object quiver_attr;
199 pybind11::object savefig_attr;
200 pybind11::object scatter_attr;
201 pybind11::object show_attr;
202 pybind11::object step_attr;
203 pybind11::object subplot_attr;
204 pybind11::object subplots_attr;
205 pybind11::object title_attr;
206 pybind11::object xlabel_attr;
207 pybind11::object xlim_attr;
208 pybind11::object ylabel_attr;
209 pybind11::object ylim_attr;
213inline axes::Axes PyPlot::axes(
const pybind11::dict &kwargs) {
214 pybind11::object ax_obj = axes_attr(**kwargs);
219inline ObjectWrapper PyPlot::axis(
const pybind11::tuple &args,
220 const pybind11::dict &kwargs) {
221 pybind11::object ret = axis_attr(*args, **kwargs);
226inline ObjectWrapper PyPlot::cla(
const pybind11::tuple &args,
227 const pybind11::dict &kwargs) {
228 pybind11::object ret = cla_attr(*args, **kwargs);
229 return ObjectWrapper(std::move(ret));
233inline ObjectWrapper PyPlot::clf(
const pybind11::tuple &args,
234 const pybind11::dict &kwargs) {
235 pybind11::object ret = clf_attr(*args, **kwargs);
236 return ObjectWrapper(std::move(ret));
240inline ObjectWrapper PyPlot::clim(
const pybind11::tuple &args,
241 const pybind11::dict &kwargs) {
242 pybind11::object ret = clim_attr(*args, **kwargs);
243 return ObjectWrapper(std::move(ret));
247inline ObjectWrapper PyPlot::colorbar(
const pybind11::tuple &args,
248 const pybind11::dict &kwargs) {
249 pybind11::object ret = colorbar_attr(*args, **kwargs);
250 return ObjectWrapper(std::move(ret));
254inline ObjectWrapper PyPlot::errorbar(
const pybind11::tuple &args,
255 const pybind11::dict &kwargs) {
256 pybind11::object ret = errorbar_attr(*args, **kwargs);
257 return ObjectWrapper(std::move(ret));
261inline std::tuple<double, double>
262PyPlot::figaspect(
const pybind11::tuple &args,
const pybind11::dict &kwargs) {
263 pybind11::list l = figaspect_attr(*args, **kwargs);
264 double width = l[0].cast<
double>();
265 double height = l[1].cast<
double>();
266 return {width, height};
270inline figure::Figure PyPlot::figure(
const pybind11::tuple &args,
271 const pybind11::dict &kwargs) {
272 pybind11::object fig_obj = figure_attr(*args, **kwargs);
273 return figure::Figure(fig_obj);
277inline axes::Axes PyPlot::gca(
const pybind11::tuple &args,
278 const pybind11::dict &kwargs) {
279 pybind11::object obj = gca_attr(*args, **kwargs);
280 return axes::Axes(obj);
284inline figure::Figure PyPlot::gcf(
const pybind11::tuple &args,
285 const pybind11::dict &kwargs) {
286 pybind11::object obj = gcf_attr(*args, **kwargs);
287 return figure::Figure(obj);
291inline ObjectWrapper PyPlot::gci(
const pybind11::tuple &args,
292 const pybind11::dict &kwargs) {
293 pybind11::object obj = gci_attr(*args, **kwargs);
298inline ObjectWrapper PyPlot::grid(
const pybind11::tuple &args,
299 const pybind11::dict &kwargs) {
300 pybind11::object obj = grid_attr(*args, **kwargs);
305inline ObjectWrapper PyPlot::imshow(
const pybind11::tuple &args,
306 const pybind11::dict &kwargs) {
307 pybind11::object obj = imshow_attr(*args, **kwargs);
312inline ObjectWrapper PyPlot::legend(
const pybind11::tuple &args,
313 const pybind11::dict &kwargs) {
314 pybind11::object ret = legend_attr(*args, **kwargs);
315 return ObjectWrapper(std::move(ret));
319inline ObjectWrapper PyPlot::pause(
const pybind11::tuple &args,
320 const pybind11::dict &kwargs) {
321 pybind11::object ret = pause_attr(*args, **kwargs);
322 return ObjectWrapper(std::move(ret));
326inline ObjectWrapper PyPlot::plot(
const pybind11::tuple &args,
327 const pybind11::dict &kwargs) {
328 pybind11::object ret = plot_attr(*args, **kwargs);
329 return ObjectWrapper(std::move(ret));
333inline ObjectWrapper PyPlot::quiver(
const pybind11::tuple &args,
334 const pybind11::dict &kwargs) {
335 pybind11::object ret = quiver_attr(*args, **kwargs);
336 return ObjectWrapper(std::move(ret));
340inline ObjectWrapper PyPlot::scatter(
const pybind11::tuple &args,
341 const pybind11::dict &kwargs) {
342 pybind11::object ret = scatter_attr(*args, **kwargs);
343 return ObjectWrapper(std::move(ret));
347inline ObjectWrapper PyPlot::savefig(
const pybind11::tuple &args,
348 const pybind11::dict &kwargs) {
349 pybind11::object ret = savefig_attr(*args, **kwargs);
350 return ObjectWrapper(std::move(ret));
354inline ObjectWrapper PyPlot::show(
const pybind11::tuple &args,
355 const pybind11::dict &kwargs) {
356 pybind11::object ret = show_attr(*args, **kwargs);
357 return ObjectWrapper(std::move(ret));
361inline ObjectWrapper PyPlot::step(
const pybind11::tuple &args,
362 const pybind11::dict &kwargs) {
363 pybind11::object ret = step_attr(*args, **kwargs);
364 return ObjectWrapper(std::move(ret));
368inline axes::Axes PyPlot::subplot(
const pybind11::dict &kwargs) {
369 return axes::Axes(subplot_attr(**kwargs));
372inline axes::Axes PyPlot::subplot(
int cri) {
373 pybind11::object obj = subplot_attr(cri);
374 return axes::Axes(obj);
378inline std::tuple<figure::Figure, axes::Axes>
379PyPlot::subplots(
const pybind11::dict &kwargs) {
380 pybind11::list ret = subplots_attr(**kwargs);
381 pybind11::object fig = ret[0];
382 pybind11::object ax = ret[1];
383 return {figure::Figure(fig), axes::Axes(ax)};
386inline std::tuple<figure::Figure, std::vector<axes::Axes>>
387PyPlot::subplots(
int r,
int c,
const pybind11::dict &kwargs) {
391 pybind11::tuple args = pybind11::make_tuple(r, c);
392 pybind11::list ret = subplots_attr(*args, **kwargs);
393 std::vector<axes::Axes> axes;
394 pybind11::object fig = ret[0];
395 figure::Figure figure(fig);
396 if (r == 1 and c == 1) {
398 axes.push_back(axes::Axes(ret[1]));
399 }
else if (r == 1 or c == 1) {
401 pybind11::list axs = ret[1];
402 for (
int i = 0; i < r * c; ++i)
403 axes.push_back(axes::Axes(axs[i]));
406 pybind11::list axs = ret[1];
407 for (pybind11::size_t i = 0; i < axs.size(); ++i) {
408 pybind11::list axsi = axs[i];
409 for (
unsigned j = 0; j < axsi.size(); ++j)
410 axes.push_back(axes::Axes(axsi[j]));
413 return {figure, axes};
417inline ObjectWrapper PyPlot::title(
const pybind11::tuple &args,
418 const pybind11::dict &kwargs) {
419 pybind11::object ret = title_attr(*args, **kwargs);
420 return ObjectWrapper(std::move(ret));
424inline ObjectWrapper PyPlot::xlabel(
const pybind11::tuple &args,
425 const pybind11::dict &kwargs) {
426 pybind11::object ret = xlabel_attr(*args, **kwargs);
427 return ObjectWrapper(std::move(ret));
431inline ObjectWrapper PyPlot::xlim(
const pybind11::tuple &args,
432 const pybind11::dict &kwargs) {
433 pybind11::object ret = xlim_attr(*args, **kwargs);
434 return ObjectWrapper(std::move(ret));
438inline ObjectWrapper PyPlot::ylabel(
const pybind11::tuple &args,
439 const pybind11::dict &kwargs) {
440 pybind11::object ret = ylabel_attr(*args, **kwargs);
441 return ObjectWrapper(std::move(ret));
445inline ObjectWrapper PyPlot::ylim(
const pybind11::tuple &args,
446 const pybind11::dict &kwargs) {
447 pybind11::object ret = ylim_attr(*args, **kwargs);
448 return ObjectWrapper(std::move(ret));
451inline PyPlot
import() {
452 auto mod = pybind11::module::import(
"matplotlib.pyplot");
453 auto g_pyplot = PyPlot(mod);
460template <
typename... ArgsT> pybind11::tuple Args(ArgsT &&...args) {
461 return pybind11::make_tuple(std::forward<ArgsT>(args)...);
464using Kwargs = pybind11::dict;
467namespace py = pybind11;
468using namespace py::literals;
A proxy class for pybind object.
Definition: common.h:50
A wrapper class for matplotlib.axes.Axes.
Definition: axes.h:30
A class corresponding to pyplot module.
Definition: pyplot.h:23