Skip to content

Commit d5fd70e

Browse files
author
MamoruSobue
committed
WIP
1 parent 197f7e3 commit d5fd70e

File tree

5 files changed

+67
-7
lines changed

5 files changed

+67
-7
lines changed

CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ if(${ADD_DEMO})
5858
find_package(xtensor 0.24.0 REQUIRED)
5959
set(CMAKE_CXX_STANDARD 17)
6060
set(CMAKE_CXX_FLAGS "-Wall -g -DUSE_GUI=${USE_GUI} -DMATPLOTLIB_MINOR_VER_GTE_4=${MATPLOTLIB_MINOR_VER_GTE_4}")
61-
add_subdirectory(gallery/lines_bars_and_markers)
61+
# add_subdirectory(gallery/lines_bars_and_markers)
6262
add_subdirectory(gallery/subplots_axes_and_figures)
63-
add_subdirectory(gallery/statistics)
64-
add_subdirectory(gallery/images_contours_and_fields)
65-
add_subdirectory(gallery/shapes_and_collections)
66-
add_subdirectory(gallery/artist_animation)
67-
add_subdirectory(gallery/mplot3d)
63+
# add_subdirectory(gallery/statistics)
64+
# add_subdirectory(gallery/images_contours_and_fields)
65+
# add_subdirectory(gallery/shapes_and_collections)
66+
# add_subdirectory(gallery/artist_animation)
67+
# add_subdirectory(gallery/mplot3d)
6868
endif()
6969

7070

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
add_demo(align_labels_demo align_labels_demo.cpp)
22
add_demo(gridspec_multicolumn gridspec_multicolumn.cpp)
33
add_demo(multiple_figs_demo multiple_figs_demo.cpp)
4+
add_demo(colorbar_placement colorbar_placement.cpp)
45

56
add_custom_target(subplots_axes_and_figures
6-
DEPENDS align_labels_demo gridspec_multicolumn multiple_figs_demo
7+
DEPENDS align_labels_demo gridspec_multicolumn multiple_figs_demo colorbar_placement
78
COMMAND align_labels_demo
89
COMMAND gridspec_multicolumn
910
COMMAND multiple_figs_demo
11+
COMMAND colorbar_placement
1012
COMMENT "subplots_axes_and_figures"
1113
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
1214
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// example from
2+
// https://matplotlib.org/stable/gallery/subplots_axes_and_figures/colorbar_placement.html
3+
4+
#include <pybind11/embed.h>
5+
#include <pybind11/stl.h>
6+
7+
#include <matplotlibcpp17/pyplot.h>
8+
9+
#include <xtensor/xrandom.hpp>
10+
11+
#include <vector>
12+
13+
namespace py = pybind11;
14+
using namespace py::literals;
15+
using namespace std;
16+
using namespace matplotlibcpp17;
17+
18+
int main() {
19+
py::scoped_interpreter guard{};
20+
auto plt = matplotlibcpp17::pyplot::import();
21+
auto [fig, axs] = plt.subplots(2, 2);
22+
const vector<string> cmaps = {"RdBu_r", "viridis"};
23+
for (auto col : {0, 1}) {
24+
for (auto row : {0, 1}) {
25+
auto x_ = xt::random::randn<double>({20, 20}) * (col + 1.0);
26+
vector<vector<double>> x(20);
27+
for (int i = 0; i < 20; ++i) {
28+
x[i].resize(20);
29+
for (int j = 0; j < 20; ++j)
30+
x[i][j] = x_(i, j);
31+
}
32+
auto &ax = axs[col + row * 2];
33+
// auto pcm = ax.pcolormesh(Args(x), Kwargs("cmap"_a = cmaps[col]));
34+
}
35+
}
36+
}

include/matplotlibcpp17/axes.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ struct DECL_STRUCT_ATTR Axes : public BaseWrapper {
123123
legend::Legend legend(const pybind11::tuple &args = pybind11::tuple(),
124124
const pybind11::dict &kwargs = pybind11::dict());
125125

126+
// pcolormesh
127+
pybind11::object pcolormesh(const pybind11::tuple &args = pybind11::tuple(),
128+
const pybind11::dict &kwargs = pybind11::dict());
129+
126130
// plot
127131
pybind11::object plot(const pybind11::tuple &args = pybind11::tuple(),
128132
const pybind11::dict &kwargs = pybind11::dict());
@@ -230,6 +234,7 @@ struct DECL_STRUCT_ATTR Axes : public BaseWrapper {
230234
LOAD_FUNC_ATTR(hist2d, self);
231235
LOAD_FUNC_ATTR(invert_yaxis, self);
232236
LOAD_FUNC_ATTR(legend, self);
237+
LOAD_FUNC_ATTR(pcolormesh, self);
233238
LOAD_FUNC_ATTR(plot, self);
234239
// NOTE: only when called with projection='3d', `plot_surface`, `plot_wireframe`, `set_zlabel` prop exists.
235240
try {
@@ -278,6 +283,7 @@ struct DECL_STRUCT_ATTR Axes : public BaseWrapper {
278283
pybind11::object hist2d_attr;
279284
pybind11::object invert_yaxis_attr;
280285
pybind11::object legend_attr;
286+
pybind11::object pcolormesh_attr;
281287
pybind11::object plot_attr;
282288
pybind11::object plot_surface_attr;
283289
pybind11::object plot_wireframe_attr;
@@ -478,6 +484,13 @@ legend::Legend Axes::legend(const pybind11::tuple &args,
478484
return legend::Legend(obj);
479485
}
480486

487+
// pcolormesh
488+
pybind11::object Axes::pcolormesh(const pybind11::tuple &args,
489+
const pybind11::dict &kwargs) {
490+
pybind11::object ret = pcolormesh_attr(*args, **kwargs);
491+
return ret;
492+
}
493+
481494
// plot
482495
pybind11::object Axes::plot(const pybind11::tuple &args,
483496
const pybind11::dict &kwargs) {

include/matplotlibcpp17/collections.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ pybind11::object PatchCollection::set_array(const pybind11::tuple &args,
7373
pybind11::object ret = set_array_attr(*args, **kwargs);
7474
return ret;
7575
}
76+
77+
/**
78+
* @brief A wrapper class for matplotlib.collections.QuadMesh
79+
**/
80+
struct DECL_STRUCT_ATTR QuadMesh : public BaseWrapper {
81+
public:
82+
QuadMesh(pybind11::object quadmesh) { self = quadmesh; }
83+
};
84+
7685
} // namespace matplotlibcpp17::collections
7786

7887
#endif /* MATPLOTLIBCPP17_COLLECTIONS_H */

0 commit comments

Comments
 (0)