8000 Merge pull request #20072 from anntzer/dd · matplotlib/matplotlib@178b46e · GitHub
[go: up one dir, main page]

Skip to content

Commit 178b46e

Browse files
authored
Merge pull request #20072 from anntzer/dd
Improve labeling in simple_axes_divider1 example.
2 parents 8188d31 + 438485f commit 178b46e

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

examples/axes_grid1/simple_axes_divider1.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@
22
=====================
33
Simple Axes Divider 1
44
=====================
5-
65
"""
76

87
from mpl_toolkits.axes_grid1 import Size, Divider
98
import matplotlib.pyplot as plt
109

1110

11+
def label_axes(ax, text):
12+
"""Place a label at the center of an axes, and remove the axis ticks."""
13+
ax.text(.5, .5, text, transform=ax.transAxes,
14+
horizontalalignment="center", verticalalignment="center")
15+
ax.tick_params(bottom=False, labelbottom=False,
16+
left=False, labelleft=False)
17+
18+
1219
##############################################################################
1320
# Fixed axes sizes; fixed paddings.
1421

1522
fig = plt.figure(figsize=(6, 6))
23+
fig.suptitle("Fixed axes sizes, fixed paddings")
1624

1725
# Sizes are in inches.
1826
horiz = [Size.Fixed(1.), Size.Fixed(.5), Size.Fixed(1.5), Size.Fixed(.5)]
@@ -24,17 +32,19 @@
2432

2533
# The rect parameter will actually be ignored and overridden by axes_locator.
2634
ax1 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=0))
35+
label_axes(ax1, "nx=0, ny=0")
2736
ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2))
37+
label_axes(ax2, "nx=0, ny=2")
2838
ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2))
39+
label_axes(ax3, "nx=2, ny=2")
2940
ax4 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, nx1=4, ny=0))
30-
31-
for ax in fig.axes:
32-
ax.tick_params(labelbottom=False, labelleft=False)
41+
label_axes(ax4, "nx=2, nx1=4, ny=0")
3342

3443
##############################################################################
3544
# Axes sizes that scale with the figure size; fixed pa CD8C ddings.
3645

3746
fig = plt.figure(figsize=(6, 6))
47+
fig.suptitle("Scalable axes sizes, fixed paddings")
3848

3949
horiz = [Size.Scaled(1.5), Size.Fixed(.5), Size.Scaled(1.), Size.Scaled(.5)]
4050
vert = [Size.Scaled(1.), Size.Fixed(.5), Size.Scaled(1.5)]
@@ -45,11 +55,12 @@
4555

4656
# The rect parameter will actually be ignored and overridden by axes_locator.
4757
ax1 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=0))
58+
label_axes(ax1, "nx=0, ny=0")
4859
ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2))
60+
label_axes(ax2, "nx=0, ny=2")
4961
ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2))
62+
label_axes(ax3, "nx=2, ny=2")
5063
ax4 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, nx1=4, ny=0))
51-
52-
for ax in fig.axes:
53-
ax.tick_params(labelbottom=False, labelleft=False)
64+
label_axes(ax4, "nx=2, nx1=4, ny=0")
5465

5566
plt.show()

0 commit comments

Comments
 (0)
0