Skip to content

Commit

Permalink
docs(autoware_pyplot): add missing readme and move the package to com…
Browse files Browse the repository at this point in the history
…mon (#9546)
  • Loading branch information
soblin authored Dec 6, 2024
1 parent 63cfff8 commit 3231bbf
Show file tree
Hide file tree
Showing 21 changed files with 43 additions and 0 deletions.
File renamed without changes.
43 changes: 43 additions & 0 deletions common/autoware_pyplot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# autoware_pyplot

This package provides C++ interface for the notable `matplotlib` using `pybind11` backend for

- creating scientific plots and images illustrating the function inputs/outputs
- debugging the output and internal data of a function before unit testing in a more lightweight manner than planning_simulator

## usage

In your main function, setup the python context and import `matplotlib`

```cpp
#include <autoware/pyplot/pyplot.hpp>
#include <pybind11/embed.h>

// in main...
py::scoped_interpreter guard{};
auto plt = autoware::pyplot::import();
```

Then you can use major functionalities of `matplotlib` almost in the same way as native python code.

```cpp
{
plt.plot(Args(std::vector<int>({1, 3, 2, 4})), Kwargs("color"_a = "blue", "linewidth"_a = 1.0));
plt.xlabel(Args("x-title"));
plt.ylabel(Args("y-title"));
plt.title(Args("title"));
plt.xlim(Args(0, 5));
plt.ylim(Args(0, 5));
plt.grid(Args(true));
plt.savefig(Args("test_single_plot.png"));
}

{
auto [fig, axes] = plt.subplots(1, 2);
auto & ax1 = axes[0];
auto & ax2 = axes[1];

ax1.set_aspect(Args("equal"));
ax2.set_aspect(Args("equal"));
}
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 3231bbf

Please sign in to comment.