Skip to content

Polar Plot #28

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,28 @@ From [gallery/subplots_axes_and_figures/align_labels_demo.cpp](https://github.co

![subplots_axes_and_figures](./gallery/images/align_labels_demo.png)

### polar plot
-[original python code](https://matplotlib.org/devdocs/gallery/pie_and_polar_charts/polar_demo.html#sphx-glr-gallery-pie-and-polar-charts-polar-demo-py)

```cpp
vector<double> r(200),theta(200);
for (int i = 0; i < 200; ++i)
{
r[i]=i*0.01;
theta[i]=2 * 3.1415 * r[i];
}
auto plt = matplotlibcpp17::pyplot::import();
auto [fig, ax] = plt.subplots(Kwargs("subplot_kw"_a=py::dict("projection"_a = "polar")));
ax.plot(Args(theta,r));
ax.set_rmax(Args(2));
ax.set_rticks(Args(py::make_tuple(0.5, 1, 1.5, 2)));
ax.grid(Args(true));
ax.set_title(Args("A line plot on a polar axis"), Kwargs("va"_a="bottom"));
plt.savefig(Args("./PolarPlot.jpg"));
plt.show();
```
![polarplot_demo](./gallery/images/PolarPlot.jpg)

### bar plot

From [gallery/lines_bars_and_markers/bar_label_demo.cpp](https://github.com/soblin/matplotlibcpp17/blob/master/gallery/lines_bars_and_markers/bar_label_demo.cpp). Here `subplots()` returns `tuple<Figure, Axes>`.
Expand Down
Binary file added gallery/images/PolarPlot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions include/matplotlibcpp17/axes.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,22 @@ struct DECL_STRUCT_ATTR Axes : public BaseWrapper {
ObjectWrapper set_yticks(const pybind11::tuple &args = pybind11::tuple(),
const pybind11::dict &kwargs = pybind11::dict());

// set_rticks
ObjectWrapper set_rticks(const pybind11::tuple &args = pybind11::tuple(),
const pybind11::dict &kwargs = pybind11::dict());

// set_rmax
ObjectWrapper set_rmax(const pybind11::tuple &args);

// set_theta_direction
ObjectWrapper set_theta_direction(const pybind11::tuple &args);

// set_rlabel_position
ObjectWrapper set_rlabel_position(const pybind11::tuple &args);

// minorticks_on
ObjectWrapper minorticks_on();

// set_zlabel
ObjectWrapper set_zlabel(const pybind11::tuple &args = pybind11::tuple(),
const pybind11::dict &kwargs = pybind11::dict());
Expand Down Expand Up @@ -293,6 +309,11 @@ struct DECL_STRUCT_ATTR Axes : public BaseWrapper {
LOAD_FUNC_ATTR(set_ylim, self);
LOAD_FUNC_ATTR(set_yscale, self);
LOAD_FUNC_ATTR(set_yticks, self);
LOAD_FUNC_ATTR(set_rticks, self);
LOAD_FUNC_ATTR(set_rmax, self);
LOAD_FUNC_ATTR(set_theta_direction, self);
LOAD_FUNC_ATTR(set_rlabel_position, self);
LOAD_FUNC_ATTR(minorticks_on, self);
LOAD_FUNC_ATTR(text, self);
LOAD_FUNC_ATTR(tick_params, self);
LOAD_FUNC_ATTR(twinx, self);
Expand Down Expand Up @@ -340,6 +361,11 @@ struct DECL_STRUCT_ATTR Axes : public BaseWrapper {
pybind11::object set_ylim_attr;
pybind11::object set_yscale_attr;
pybind11::object set_yticks_attr;
pybind11::object set_rticks_attr;
pybind11::object set_rmax_attr;
pybind11::object set_theta_direction_attr;
pybind11::object set_rlabel_position_attr;
pybind11::object minorticks_on_attr;
pybind11::object set_zlabel_attr;
pybind11::object set_zlim_attr;
pybind11::object text_attr;
Expand Down Expand Up @@ -681,6 +707,37 @@ ObjectWrapper Axes::set_yticks(const pybind11::tuple &args,
return ObjectWrapper(std::move(ret));
}

// set_rticks
ObjectWrapper Axes::set_rticks(const pybind11::tuple &args,
const pybind11::dict &kwargs) {
pybind11::object ret = set_rticks_attr(*args, **kwargs);
return ObjectWrapper(std::move(ret));
}

// set_rmax
ObjectWrapper Axes::set_rmax(const pybind11::tuple &args) {
pybind11::object ret = set_rmax_attr(*args);
return ObjectWrapper(std::move(ret));
}

// set_theta_direction
ObjectWrapper Axes::set_theta_direction(const pybind11::tuple &args) {
pybind11::object ret = set_theta_direction_attr(*args);
return ObjectWrapper(std::move(ret));
}

// set_rlabel_position
ObjectWrapper Axes::set_rlabel_position(const pybind11::tuple &args) {
pybind11::object ret = set_rlabel_position_attr(*args);
return ObjectWrapper(std::move(ret));
}

// minorticks_on
ObjectWrapper Axes::minorticks_on() {
pybind11::object ret = minorticks_on_attr();
return ObjectWrapper(std::move(ret));
}

// set_zlabel
ObjectWrapper Axes::set_zlabel(const pybind11::tuple &args,
const pybind11::dict &kwargs) {
Expand Down