-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add additional functions #23
Conversation
Hi @jurihock thanks for you PR ! https://matplotlib.org/stable/gallery/index.html I want to add them in |
I plan to use it here instead of the current matplotlibcpp binding. But for that I need at least imshow and clim. I'm not familiar with xtensor, but numcpp works fine to draw a 2D sombrero: #include <matplotlibcpp17/pyplot.h>
#include <NumCpp.hpp>
namespace py = pybind11;
void test()
{
py::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);
auto plot = matplotlibcpp17::pyplot::import();
plot.imshow(Args(pysombrero), Kwargs(
"extent"_a = py::make_tuple(-1, +1, -1, +1),
"cmap"_a = "inferno"));
plot.colorbar();
plot.clim(py::make_tuple(-4e-10, +3e-9));
plot.show();
} Maybe something like that would be a suitable example for the gallery... |
LGTM. Then you can rename I think I'll add some examples from the official matplotlib gallery using |
Okay, thanks! I'm using the tagged NumCpp 2.8.0 version. In order to build the provided example you may have to introduce following defines: // disable boost
#define NUMCPP_NO_USE_BOOST
// enable nc::pybindInterface::nc2pybind
#define NUMCPP_INCLUDE_PYBIND_PYTHON_INTERFACE |
There are two colorbar functions in matplotlib:
Figure.colorbar
(as already implemented) andpyplot.colorbar
(proposed in this pr). Themappable
argument is mandatory inFigure.colorbar
but optional inpyplot.colorbar
, which internally defaults topyplot.gci
. See also matplotlib.pyplot.colorbar.