Skip to content

Commit

Permalink
differences for PR #650
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Mar 17, 2024
1 parent df94160 commit 8b0ab09
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion 09-plotting.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,22 @@ matplotlib will make this variable refer to a new empty figure.
Therefore, make sure you call `plt.savefig` before the plot is displayed to
the screen, otherwise you may find a file with an empty plot.

Sometimes, some elements of the figure may get truncated when saving the figure to a file. You can find an in-depth explanation why this happens [here](https://matplotlib.org/stable/users/explain/axes/tight_layout_guide.html). To avoid this, we can call `plt.tight_layout` before `plt.savefig` to make sure that everything fits into the figure area.

```python
plt.tight_layout()
plt.savefig('my_figure.png')
```

When using dataframes, data is often generated and plotted to screen in one line.
In addition to using `plt.savefig`, we can save a reference to the current figure
in a local variable (with `plt.gcf`) and call the `savefig` class method from
in a local variable (with `plt.gcf`) and call the `tight_layout` and `savefig` class method from
that variable to save the figure to file.

```python
data.plot(kind='bar')
fig = plt.gcf() # get current figure
fig.tight_layout()
fig.savefig('my_figure.png')
```

Expand Down
2 changes: 1 addition & 1 deletion md5sum.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"episodes/06-libraries.md" "96899c58843e51f10eb84a8ac20ebb90" "site/built/06-libraries.md" "2023-05-02"
"episodes/07-reading-tabular.md" "b5b65e50037a583dfc5a3a879e4404b0" "site/built/07-reading-tabular.md" "2023-05-02"
"episodes/08-data-frames.md" "af0057242e5f63f0c049f58ad66f1cbb" "site/built/08-data-frames.md" "2023-08-29"
"episodes/09-plotting.md" "d701a7c8d39329d1786b48b32063ffc8" "site/built/09-plotting.md" "2024-03-17"
"episodes/09-plotting.md" "d658f02ee6086122c2af0fdbc1c07609" "site/built/09-plotting.md" "2024-03-17"
"episodes/10-lunch.md" "0624bfa89e628df443070e8c44271b33" "site/built/10-lunch.md" "2023-05-02"
"episodes/11-lists.md" "1257daeb542377a3b04c6bec0d0ffee1" "site/built/11-lists.md" "2023-07-24"
"episodes/12-for-loops.md" "1da6e4e57a25f8d4fd64802c2eb682c4" "site/built/12-for-loops.md" "2023-05-02"
Expand Down

0 comments on commit 8b0ab09

Please sign in to comment.