Skip to content
Snippets Groups Projects
Unverified Commit bb9e692c authored by Jürgen Hock's avatar Jürgen Hock Committed by GitHub
Browse files

Add additional functions (#23)

* Add imshow function
* Add clim function
* Add gci function
* Add colorbar function
* Add sombrero example
parent 990c2568
Branches
No related tags found
No related merge requests found
#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;
}
\ No newline at end of file
gallery/contrib/sombrero.png

45 KiB

......@@ -44,6 +44,14 @@ public:
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 @@ public:
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 @@ private:
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 @@ private:
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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment