diff --git a/gallery/lines_bars_and_markers/CMakeLists.txt b/gallery/lines_bars_and_markers/CMakeLists.txt index c936eb7..ca61696 100644 --- a/gallery/lines_bars_and_markers/CMakeLists.txt +++ b/gallery/lines_bars_and_markers/CMakeLists.txt @@ -8,9 +8,10 @@ add_demo(scatter_with_legend scatter_with_legend.cpp) add_demo(scatter_hist scatter_hist.cpp) add_demo(errorbar_limits_simple errorbar_limits_simple.cpp) add_demo(errorbar_subsample errorbar_subsample.cpp) +add_demo(step_demo step_demo.cpp) add_custom_target(lines_bars_and_markers - DEPENDS bar_label_demo fill simple_plot scatter_symbol fill_between_demo fill_betweenx_demo scatter_with_legend scatter_hist errorbar_limits_simple errorbar_subsample + DEPENDS bar_label_demo fill simple_plot scatter_symbol fill_between_demo fill_betweenx_demo scatter_with_legend scatter_hist errorbar_limits_simple errorbar_subsample step_demo COMMAND bar_label_demo COMMAND fill COMMAND simple_plot @@ -21,6 +22,7 @@ add_custom_target(lines_bars_and_markers COMMAND scatter_hist COMMAND errorbar_limits_simple COMMAND errorbar_subsample + COMMAND step_demo COMMENT "running lines_bars_and_markers" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../images" ) diff --git a/gallery/lines_bars_and_markers/step_demo.cpp b/gallery/lines_bars_and_markers/step_demo.cpp new file mode 100644 index 0000000..e5da76b --- /dev/null +++ b/gallery/lines_bars_and_markers/step_demo.cpp @@ -0,0 +1,37 @@ +// example from +// https://matplotlib.org/stable/gallery/lines_bars_and_markers/step_demo.html + +#include + +#include +#include + +#include + +using namespace std; +using namespace matplotlibcpp17; + +int main() { + py::scoped_interpreter guard{}; + auto plt = pyplot::import(); + + auto x_ = xt::arange(14) * 1.0; + auto y_ = xt::sin(x_ / 2.0); + auto y1_ = y_ + 1.0, y2_ = y_ + 2.0; + vector x(x_.begin(), x_.end()), y(y_.begin(), y_.end()), + y1(y1_.begin(), y1_.end()), y2(y2_.begin(), y2_.end()); + + plt.step(Args(x, y2), Kwargs("label"_a = "pre (default)")); + plt.plot(Args(x, y2, "o--"), Kwargs("color"_a = "grey", "alpha"_a = 0.3)); + + plt.step(Args(x, y1), Kwargs("where"_a = "mid", "label"_a = "mid")); + plt.plot(Args(x, y1, "o--"), Kwargs("color"_a = "grey", "alpha"_a = 0.3)); + + plt.step(Args(x, y), Kwargs("where"_a = "post", "label"_a = "post")); + plt.plot(Args(x, y, "o--"), Kwargs("color"_a = "grey", "alpha"_a = 0.3)); + + plt.grid(Args(), Kwargs("axis"_a = "x", "color"_a = "0.95")); + plt.legend(Args(), Kwargs("title"_a = "Parameter where:")); + plt.title(Args("plt.step(where...)")); + plt.show(); +} diff --git a/include/matplotlibcpp17/pyplot.h b/include/matplotlibcpp17/pyplot.h index 1fb7d03..9e8da89 100644 --- a/include/matplotlibcpp17/pyplot.h +++ b/include/matplotlibcpp17/pyplot.h @@ -65,6 +65,10 @@ struct DECL_STRUCT_ATTR PyPlot { figure::Figure gcf(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()); + // legend pybind11::object legend(const pybind11::tuple &args = pybind11::tuple(), const pybind11::dict &kwargs = pybind11::dict()); @@ -93,6 +97,10 @@ struct DECL_STRUCT_ATTR PyPlot { pybind11::object show(const pybind11::tuple &args = pybind11::tuple(), const pybind11::dict &kwargs = pybind11::dict()); + // step + pybind11::object step(const pybind11::tuple &args = pybind11::tuple(), + const pybind11::dict &kwargs = pybind11::dict()); + // subplot axes::Axes subplot(const pybind11::dict &kwargs = pybind11::dict()); axes::Axes subplot(int cri); @@ -103,6 +111,10 @@ struct DECL_STRUCT_ATTR PyPlot { std::tuple> subplots(int r, int c, const pybind11::dict &kwargs = pybind11::dict()); + // title + pybind11::object title(const pybind11::tuple &args = pybind11::tuple(), + const pybind11::dict &kwargs = pybind11::dict()); + // xlabel pybind11::object xlabel(const pybind11::tuple &args = pybind11::tuple(), const pybind11::dict &kwargs = pybind11::dict()); @@ -130,6 +142,7 @@ struct DECL_STRUCT_ATTR PyPlot { LOAD_FUNC_ATTR(figure, mod); LOAD_FUNC_ATTR(gca, mod); LOAD_FUNC_ATTR(gcf, mod); + LOAD_FUNC_ATTR(grid, mod); LOAD_FUNC_ATTR(legend, mod); LOAD_FUNC_ATTR(pause, mod); LOAD_FUNC_ATTR(plot, mod); @@ -137,8 +150,10 @@ struct DECL_STRUCT_ATTR PyPlot { LOAD_FUNC_ATTR(savefig, mod); LOAD_FUNC_ATTR(scatter, mod); LOAD_FUNC_ATTR(show, mod); + LOAD_FUNC_ATTR(step, mod); LOAD_FUNC_ATTR(subplot, mod); LOAD_FUNC_ATTR(subplots, mod); + LOAD_FUNC_ATTR(title, mod); LOAD_FUNC_ATTR(xlabel, mod); LOAD_FUNC_ATTR(xlim, mod); LOAD_FUNC_ATTR(ylabel, mod); @@ -154,6 +169,7 @@ struct DECL_STRUCT_ATTR PyPlot { pybind11::object figure_attr; pybind11::object gca_attr; pybind11::object gcf_attr; + pybind11::object grid_attr; pybind11::object legend_attr; pybind11::object pause_attr; pybind11::object plot_attr; @@ -161,8 +177,10 @@ struct DECL_STRUCT_ATTR PyPlot { pybind11::object savefig_attr; pybind11::object scatter_attr; pybind11::object show_attr; + pybind11::object step_attr; pybind11::object subplot_attr; pybind11::object subplots_attr; + pybind11::object title_attr; pybind11::object xlabel_attr; pybind11::object xlim_attr; pybind11::object ylabel_attr; @@ -233,6 +251,13 @@ figure::Figure PyPlot::gcf(const pybind11::tuple &args, return figure::Figure(obj); } +// grid +pybind11::object PyPlot::grid(const pybind11::tuple &args, + const pybind11::dict &kwargs) { + pybind11::object obj = grid_attr(*args, **kwargs); + return obj; +} + // legend pybind11::object PyPlot::legend(const pybind11::tuple &args, const pybind11::dict &kwargs) { @@ -282,6 +307,13 @@ pybind11::object PyPlot::show(const pybind11::tuple &args, return ret; } +// step +pybind11::object PyPlot::step(const pybind11::tuple &args, + const pybind11::dict &kwargs) { + pybind11::object ret = step_attr(*args, **kwargs); + return ret; +} + // subplot axes::Axes PyPlot::subplot(const pybind11::dict &kwargs) { return axes::Axes(subplot_attr(**kwargs)); @@ -331,6 +363,13 @@ PyPlot::subplots(int r, int c, const pybind11::dict &kwargs) { return {figure, axes}; } +// title +pybind11::object PyPlot::title(const pybind11::tuple &args, + const pybind11::dict &kwargs) { + pybind11::object ret = title_attr(*args, **kwargs); + return ret; +} + // xlabel pybind11::object PyPlot::xlabel(const pybind11::tuple &args, const pybind11::dict &kwargs) {