-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,436 additions
and
1,372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Figure and Axis Manipulation | ||
|
||
## Update plot with returned Figure and Axes | ||
|
||
You are free to modify the figure generated by `Waffle` class. | ||
You may get all axes in the figure through property [Figure.axes](https://matplotlib.org/stable/api/figure_api.html#matplotlib.figure.Figure.axes), and modify them through the list. | ||
|
||
For example, if you would like to remove the auto-generated legend, and save the figure into a file, you can update the axis through `axes` property and then call `savefig()` with the returned figure: | ||
|
||
```python | ||
fig = plt.figure( | ||
FigureClass=Waffle, | ||
rows=5, | ||
columns=10, | ||
values={'Cat1': 30, 'Cat2': 16, 'Cat3': 4}, | ||
) | ||
|
||
# Remove legend | ||
fig.axes[0].get_legend().remove() | ||
|
||
# Save the figure into a file | ||
fig.savefig("my_plot.png") | ||
``` | ||
|
||
--- | ||
|
||
## Make Waffle on Existed Axis | ||
|
||
Sometimes you might have figure and axis created already, and you would like to plot waffle chart on top of | ||
it, without creating a new figure. In this case, you may use `Waffle.make_waffle()` function, which accepts axis `ax` and other arguments available in `Waffle`. | ||
|
||
> **_NOTE:_** `Waffle.make_waffle()` is a classmethod, and you should call it without creating a new `Waffle` instance. | ||
> **_NOTE:_** The only argument that is available in Waffle but unsupported in `Waffle.make_waffle()` is `plots`, since it only accept one axis. Thus, this function can only generate waffle chart in a single plot. | ||
Below is an example showing that you may create and modify the figure and axis first, and then pass the axis to `Waffle.make_waffle()` for waffle chart plotting. | ||
|
||
```python | ||
fig = plt.figure() | ||
ax = fig.add_subplot(111) | ||
|
||
# Modify existed axis | ||
ax.set_title("Axis Title") | ||
ax.set_aspect(aspect="equal") | ||
|
||
Waffle.make_waffle( | ||
ax=ax, # pass axis to make_waffle | ||
rows=5, | ||
columns=10, | ||
values=[30, 16, 4], | ||
title={"label": "Waffle Title", "loc": "left"} | ||
) | ||
``` | ||
|
||
<img class="img_middle" alt="With list values" src="https://raw.githubusercontent.com/gyli/PyWaffle/master/examples/docs/plot_on_existed_axis.svg?sanitize=true"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.