diff --git a/gallery/contrib/sombrero,cpp b/gallery/contrib/sombrero,cpp new file mode 100644 index 0000000..8b03ff3 --- /dev/null +++ b/gallery/contrib/sombrero,cpp @@ -0,0 +1,35 @@ +#include +#include + +int main() +{ + pybind11::scoped_interpreter guard{}; + + const int size = 1000; + const double sigma = 100; + + const auto i = nc::arange(size) - (0.5 * size); + const auto [x, y] = nc::meshgrid(i, i); + + const auto xy = (nc::power(x, 2) + nc::power(y, 2)) / (-2.0 * nc::power(sigma, 2)); + + const auto sombrero = nc::exp(xy) * (xy + 1.0) / (std::acos(-1.0) * nc::power(sigma, 4)); + const auto pysombrero = nc::pybindInterface::nc2pybind(sombrero); + + const auto min = nc::min(sombrero)[0]; + const auto max = nc::max(sombrero)[0]; + + auto plt = matplotlibcpp17::pyplot::import(); + + plt.imshow(Args(pysombrero), Kwargs( + "extent"_a = pybind11::make_tuple(-1, +1, -1, +1), + "cmap"_a = "inferno")); + + plt.colorbar(); + + plt.clim(pybind11::make_tuple(min * 0.8, max * 0.8)); + + plt.show(); + + return 0; +} \ No newline at end of file diff --git a/gallery/contrib/sombrero.png b/gallery/contrib/sombrero.png new file mode 100644 index 0000000..16c7610 Binary files /dev/null and b/gallery/contrib/sombrero.png differ diff --git a/include/matplotlibcpp17/pyplot.h b/include/matplotlibcpp17/pyplot.h index 9e8da89..7fa4ca0 100644 --- a/include/matplotlibcpp17/pyplot.h +++ b/include/matplotlibcpp17/pyplot.h @@ -44,6 +44,14 @@ struct DECL_STRUCT_ATTR PyPlot { pybind11::object clf(const pybind11::tuple &args = pybind11::tuple(), const pybind11::dict &kwargs = pybind11::dict()); + // clim + pybind11::object clim(const pybind11::tuple &args = pybind11::tuple(), + const pybind11::dict &kwargs = pybind11::dict()); + + // colorbar + pybind11::object colorbar(const pybind11::tuple &args = pybind11::tuple(), + const pybind11::dict &kwargs = pybind11::dict()); + // errorbar pybind11::object errorbar(const pybind11::tuple &args = pybind11::tuple(), const pybind11::dict &kwargs = pybind11::dict()); @@ -65,10 +73,18 @@ struct DECL_STRUCT_ATTR PyPlot { figure::Figure gcf(const pybind11::tuple &args = pybind11::tuple(), const pybind11::dict &kwargs = pybind11::dict()); + // gci + pybind11::object gci(const pybind11::tuple &args = pybind11::tuple(), + const pybind11::dict &kwargs = pybind11::dict()); + // grid pybind11::object grid(const pybind11::tuple &args = pybind11::tuple(), const pybind11::dict &kwargs = pybind11::dict()); + // imshow + pybind11::object imshow(const pybind11::tuple &args = pybind11::tuple(), + const pybind11::dict &kwargs = pybind11::dict()); + // legend pybind11::object legend(const pybind11::tuple &args = pybind11::tuple(), const pybind11::dict &kwargs = pybind11::dict()); @@ -137,12 +153,16 @@ struct DECL_STRUCT_ATTR PyPlot { LOAD_FUNC_ATTR(axis, mod); LOAD_FUNC_ATTR(cla, mod); LOAD_FUNC_ATTR(clf, mod); + LOAD_FUNC_ATTR(clim, mod); + LOAD_FUNC_ATTR(colorbar, mod); LOAD_FUNC_ATTR(errorbar, mod); LOAD_FUNC_ATTR(figaspect, mod); LOAD_FUNC_ATTR(figure, mod); LOAD_FUNC_ATTR(gca, mod); LOAD_FUNC_ATTR(gcf, mod); + LOAD_FUNC_ATTR(gci, mod); LOAD_FUNC_ATTR(grid, mod); + LOAD_FUNC_ATTR(imshow, mod); LOAD_FUNC_ATTR(legend, mod); LOAD_FUNC_ATTR(pause, mod); LOAD_FUNC_ATTR(plot, mod); @@ -164,12 +184,16 @@ struct DECL_STRUCT_ATTR PyPlot { pybind11::object axis_attr; pybind11::object cla_attr; pybind11::object clf_attr; + pybind11::object clim_attr; + pybind11::object colorbar_attr; pybind11::object errorbar_attr; pybind11::object figaspect_attr; pybind11::object figure_attr; pybind11::object gca_attr; pybind11::object gcf_attr; + pybind11::object gci_attr; pybind11::object grid_attr; + pybind11::object imshow_attr; pybind11::object legend_attr; pybind11::object pause_attr; pybind11::object plot_attr; @@ -214,6 +238,20 @@ pybind11::object PyPlot::clf(const pybind11::tuple &args, return ret; } +// clim +pybind11::object PyPlot::clim(const pybind11::tuple &args, + const pybind11::dict &kwargs) { + pybind11::object ret = clim_attr(*args, **kwargs); + return ret; +} + +// colorbar +pybind11::object PyPlot::colorbar(const pybind11::tuple &args, + const pybind11::dict &kwargs) { + pybind11::object ret = colorbar_attr(*args, **kwargs); + return ret; +} + // errorbar pybind11::object PyPlot::errorbar(const pybind11::tuple &args, const pybind11::dict &kwargs) { @@ -251,6 +289,13 @@ figure::Figure PyPlot::gcf(const pybind11::tuple &args, return figure::Figure(obj); } +// gci +pybind11::object PyPlot::gci(const pybind11::tuple &args, + const pybind11::dict &kwargs) { + pybind11::object obj = gci_attr(*args, **kwargs); + return obj; +} + // grid pybind11::object PyPlot::grid(const pybind11::tuple &args, const pybind11::dict &kwargs) { @@ -258,6 +303,13 @@ pybind11::object PyPlot::grid(const pybind11::tuple &args, return obj; } +// imshow +pybind11::object PyPlot::imshow(const pybind11::tuple &args, + const pybind11::dict &kwargs) { + pybind11::object obj = imshow_attr(*args, **kwargs); + return obj; +} + // legend pybind11::object PyPlot::legend(const pybind11::tuple &args, const pybind11::dict &kwargs) {