DOC: add tutorial and example · matplotlib/matplotlib@740ec16 · GitHub
Skip to content

Commit 740ec16

Browse files
committed
DOC: add tutorial and example
1 parent a812108 commit 740ec16

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

doc/users/next_whats_new/subplot_get_gridspec.rst

Lines changed: 1 addition & 1 deletion
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
==================================================
3+
Combining two subplots using subplots and GridSpec
4+
==================================================
5+
6+
Sometimes we want to combine two subplots in an axes layout created with
7+
`~.Figure.subplots`. We can get the `~.gridspec.GridSpec` from the axes
8+
and then remove the covered axes and fill the gap with a new bigger axes.
9+
Here we create a layout with the bottom two axes in the last column combined.
10+
11+
See: :doc:`/tutorials/intermediate/gridspec`
12+
"""
13+
import matplotlib.pyplot as plt
14+
15+
fig, axs = plt.subplots(ncols=3, nrows=3)
16+
gs = axs[1, 2].get_gridspec()
17+
# remove the underlying axes
18+
for ax in axs[1:, -1]:
19+
ax.remove()
20+
axbig = fig.add_subplot(gs[1:, -1])
21+
axbig.annotate('Big Axes \nGridSpec[1:, -1]', (0.1, 0.5),
22+
xycoords='axes fraction', va='center')
23+
24+
fig.tight_layout()

tutorials/intermediate/gridspec.py

Lines changed: 16 additions & 0 deletions

0 commit comments

Comments
 (0)