Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5e8e95f

Browse files
committed
Cleanup the GridSpec demos.
Merged demo_gridspec03 and demo_gridspec05. Gave them slightly more meaningful titles.
1 parent 521b60a commit 5e8e95f

File tree

5 files changed

+51
-61
lines changed

5 files changed

+51
-61
lines changed

doc/users/prev_whats_new/whats_new_1.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Jae-Joon Lee has written :mod:`~matplotlib.gridspec`, a new module for
2525
doing complex subplot layouts, featuring row and column spans and
2626
more. See :doc:`/tutorials/intermediate/gridspec` for a tutorial overview.
2727

28-
.. figure:: ../../gallery/userdemo/images/sphx_glr_demo_gridspec01_000.png
28+
.. figure:: ../../gallery/userdemo/images/sphx_glr_demo_gridspec01_001.png
2929
:target: ../../gallery/userdemo/demo_gridspec01.html
3030
:align: center
3131
:scale: 50

examples/userdemo/demo_gridspec01.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
"""
2-
===============
3-
Demo Gridspec01
4-
===============
2+
=================
3+
subplot2grid demo
4+
=================
55
6+
This example demonstrates the use of `plt.subplot2grid` to generate subplots.
7+
Using `GridSpec`, as demonstrated in :doc:`/gallery/userdemo/demo_gridspec03`
8+
is generally preferred.
69
"""
10+
711
import matplotlib.pyplot as plt
812

913

10-
def make_ticklabels_invisible(fig):
14+
def annotate_axes(fig):
1115
for i, ax in enumerate(fig.axes):
1216
ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")
1317
ax.tick_params(labelbottom=False, labelleft=False)
1418

1519

16-
fig = plt.figure(0)
20+
fig = plt.figure()
1721
ax1 = plt.subplot2grid((3, 3), (0, 0), colspan=3)
1822
ax2 = plt.subplot2grid((3, 3), (1, 0), colspan=2)
1923
ax3 = plt.subplot2grid((3, 3), (1, 2), rowspan=2)
2024
ax4 = plt.subplot2grid((3, 3), (2, 0))
2125
ax5 = plt.subplot2grid((3, 3), (2, 1))
2226

23-
fig.suptitle("subplot2grid")
24-
make_ticklabels_invisible(fig)
27+
annotate_axes(fig)
2528

2629
plt.show()

examples/userdemo/demo_gridspec03.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,50 @@
11
"""
2-
===============
3-
Demo Gridspec03
4-
===============
5-
2+
=============
3+
GridSpec demo
4+
=============
5+
6+
This example demonstrates the use of `GridSpec` to generate subplots,
7+
the control of the relative sizes of subplots with *width_ratios* and
8+
*height_ratios*, and the control of the spacing around and between subplots
9+
using subplot params (*left*, *right*, *bottom*, *top*, *wspace*, and
10+
*hspace*).
611
"""
12+
713
import matplotlib.pyplot as plt
814
from matplotlib.gridspec import GridSpec
915

1016

11-
def make_ticklabels_invisible(fig):
17+
def annotate_axes(fig):
1218
for i, ax in enumerate(fig.axes):
1319
ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")
1420
ax.tick_params(labelbottom=False, labelleft=False)
1521

1622

17-
# demo 3 : gridspec with subplotpars set.
18-
1923
fig = plt.figure()
24+
fig.suptitle("Controlling subplot sizes with width_ratios and height_ratios")
25+
26+
gs = GridSpec(2, 2, width_ratios=[1, 2], height_ratios=[4, 1])
27+
ax1 = fig.add_subplot(gs[0])
28+
ax2 = fig.add_subplot(gs[1])
29+
ax3 = fig.add_subplot(gs[2])
30+
ax4 = fig.add_subplot(gs[3])
2031

21-
fig.suptitle("GridSpec w/ different subplotpars")
32+
annotate_axes(fig)
33+
34+
35+
fig = plt.figure()
36+
fig.suptitle("Controlling spacing around and between subplots")
2237

23-
gs1 = GridSpec(3, 3)
24-
gs1.update(left=0.05, right=0.48, wspace=0.05)
25-
ax1 = plt.subplot(gs1[:-1, :])
26-
ax2 = plt.subplot(gs1[-1, :-1])
27-
ax3 = plt.subplot(gs1[-1, -1])
38+
gs1 = GridSpec(3, 3, left=0.05, right=0.48, wspace=0.05)
39+
ax1 = fig.add_subplot(gs1[:-1, :])
40+
ax2 = fig.add_subplot(gs1[-1, :-1])
41+
ax3 = fig.add_subplot(gs1[-1, -1])
2842

29-
gs2 = GridSpec(3, 3)
30-
gs2.update(left=0.55, right=0.98, hspace=0.05)
31-
ax4 = plt.subplot(gs2[:, :-1])
32-
ax5 = plt.subplot(gs2[:-1, -1])
33-
ax6 = plt.subplot(gs2[-1, -1])
43+
gs2 = GridSpec(3, 3, left=0.55, right=0.98, hspace=0.05)
44+
ax4 = fig.add_subplot(gs2[:, :-1])
45+
ax5 = fig.add_subplot(gs2[:-1, -1])
46+
ax6 = fig.add_subplot(gs2[-1, -1])
3447

35-
make_ticklabels_invisible(fig)
48+
annotate_axes(fig)
3649

3750
plt.show()

examples/userdemo/demo_gridspec05.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

examples/userdemo/demo_gridspec06.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
"""
2-
===============
3-
Demo Gridspec06
4-
===============
1+
r"""
2+
================
3+
Nested GridSpecs
4+
================
55
6+
This example demonstrates the use of nested `GridSpec`\s.
67
"""
8+
79
import matplotlib.pyplot as plt
810
import matplotlib.gridspec as gridspec
911
import numpy as np
@@ -26,15 +28,15 @@ def squiggle_xy(a, b, c, d):
2628
a = i // 4 + 1
2729
b = i % 4 + 1
2830
for j, (c, d) in enumerate(product(range(1, 4), repeat=2)):
29-
ax = plt.Subplot(fig, inner_grid[j])
31+
ax = fig.add_subplot(inner_grid[j])
3032
ax.plot(*squiggle_xy(a, b, c, d))
3133
ax.set_xticks([])
3234
ax.set_yticks([])
3335
fig.add_subplot(ax)
3436

3537
all_axes = fig.get_axes()
3638

37-
#show only the outside spines
39+
# show only the outside spines
3840
for ax in all_axes:
3941
for sp in ax.spines.values():
4042
sp.set_visible(False)

0 commit comments

Comments
 (0)