Skip to content

Add additional functions #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions gallery/contrib/sombrero,cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <matplotlibcpp17/pyplot.h>
#include <NumCpp.hpp>

int main()
{
pybind11::scoped_interpreter guard{};

const int size = 1000;
const double sigma = 100;

const auto i = nc::arange<double>(size) - (0.5 * size);
const auto [x, y] = nc::meshgrid<double>(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;
}
Binary file added gallery/contrib/sombrero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions include/matplotlibcpp17/pyplot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -251,13 +289,27 @@ 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) {
pybind11::object obj = grid_attr(*args, **kwargs);
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) {
Expand Down