matplotlibcpp17
figure.h
1
5#pragma once
6
7#include <matplotlibcpp17/axes.h>
8#include <matplotlibcpp17/common.h>
9#include <matplotlibcpp17/gridspec.h>
10
11#include <pybind11/pybind11.h>
12
13namespace matplotlibcpp17::figure {
14
18struct DECL_STRUCT_ATTR Figure : public BaseWrapper {
19public:
20 Figure(const pybind11::object &figure) {
21 self = figure;
22 load_attrs();
23 }
24 Figure(pybind11::object &&figure) {
25 self = std::move(figure);
26 load_attrs();
27 }
28 // add_axes
29 axes::Axes add_axes(const pybind11::tuple &args = pybind11::tuple(),
30 const pybind11::dict &kwargs = pybind11::dict());
31
32 // add_gridspec
34 add_gridspec(int nrow, int ncol,
35 const pybind11::dict &kwargs = pybind11::dict());
36
37 // add_subplot
38 axes::Axes add_subplot(const pybind11::tuple &args = pybind11::tuple(),
39 const pybind11::dict &kwargs = pybind11::dict());
40
41 // align_labels
42 ObjectWrapper align_labels(const pybind11::tuple &args = pybind11::tuple(),
43 const pybind11::dict &kwargs = pybind11::dict());
44
45 // colorbar
46 ObjectWrapper colorbar(const pybind11::tuple &args = pybind11::tuple(),
47 const pybind11::dict &kwargs = pybind11::dict());
48
49 // savefig
50 ObjectWrapper savefig(const pybind11::tuple &args = pybind11::tuple(),
51 const pybind11::dict &kwargs = pybind11::dict());
52
53 // suptitle
54 ObjectWrapper suptitle(const pybind11::tuple &args = pybind11::tuple(),
55 const pybind11::dict &kwargs = pybind11::dict());
56
57 // tight_layout
58 ObjectWrapper tight_layout(const pybind11::tuple &args = pybind11::tuple(),
59 const pybind11::dict &kwargs = pybind11::dict());
60
61private:
62 void load_attrs() {
63 LOAD_FUNC_ATTR(add_axes, self);
64 LOAD_FUNC_ATTR(add_gridspec, self);
65 LOAD_FUNC_ATTR(add_subplot, self);
66 LOAD_FUNC_ATTR(align_labels, self);
67 LOAD_FUNC_ATTR(colorbar, self);
68 LOAD_FUNC_ATTR(savefig, self);
69 LOAD_FUNC_ATTR(suptitle, self);
70 LOAD_FUNC_ATTR(tight_layout, self);
71 }
72 pybind11::object add_axes_attr;
73 pybind11::object add_gridspec_attr;
74 pybind11::object add_subplot_attr;
75 pybind11::object align_labels_attr;
76 pybind11::object colorbar_attr;
77 pybind11::object savefig_attr;
78 pybind11::object suptitle_attr;
79 pybind11::object tight_layout_attr;
80};
81
82// add_axes
83inline axes::Axes Figure::add_axes(const pybind11::tuple &args,
84 const pybind11::dict &kwargs) {
85 pybind11::object obj = add_axes_attr(*args, **kwargs);
86 return axes::Axes(obj);
87}
88
89// add_gridspec
90inline gridspec::GridSpec Figure::add_gridspec(int nrow, int ncol,
91 const pybind11::dict &kwargs) {
92 return gridspec::GridSpec(nrow, ncol, kwargs);
93}
94
95// add_subplot
96inline axes::Axes Figure::add_subplot(const pybind11::tuple &args,
97 const pybind11::dict &kwargs) {
98 pybind11::object obj = add_subplot_attr(*args, **kwargs);
99 return axes::Axes(obj);
100}
101
102// align_labels
103inline ObjectWrapper Figure::align_labels(const pybind11::tuple &args,
104 const pybind11::dict &kwargs) {
105 pybind11::object ret = align_labels_attr(*args, **kwargs);
106 return ObjectWrapper(std::move(ret));
107}
108
109// colorbar
110inline ObjectWrapper Figure::colorbar(const pybind11::tuple &args,
111 const pybind11::dict &kwargs) {
112 pybind11::object ret = colorbar_attr(*args, **kwargs);
113 return ObjectWrapper(std::move(ret));
114}
115
116// savefig
117inline ObjectWrapper Figure::savefig(const pybind11::tuple &args,
118 const pybind11::dict &kwargs) {
119 pybind11::object ret = savefig_attr(*args, **kwargs);
120 return ObjectWrapper(std::move(ret));
121}
122
123// suptitle
124inline ObjectWrapper Figure::suptitle(const pybind11::tuple &args,
125 const pybind11::dict &kwargs) {
126 pybind11::object ret = suptitle_attr(*args, **kwargs);
127 return ObjectWrapper(std::move(ret));
128}
129
130// tight_layout
131inline ObjectWrapper Figure::tight_layout(const pybind11::tuple &args,
132 const pybind11::dict &kwargs) {
133 pybind11::object ret = tight_layout_attr(*args, **kwargs);
134 return ObjectWrapper(std::move(ret));
135}
136
137} // namespace matplotlibcpp17::figure
A base class for python wrapper classes.
Definition: common.h:39
A proxy class for pybind object.
Definition: common.h:50
A wrapper class for matplotlib.axes.Axes.
Definition: axes.h:30
A wrapper class for matplotlib.figure.Figure.
Definition: figure.h:18
A wrapper class for matplotlib.gridspec.GridSpec.
Definition: gridspec.h:25