Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f123ee8

Browse filesBrowse files
committed
Improve labeling in simple_axes_divider1 example.
1 parent 1b0b8d4 commit f123ee8
Copy full SHA for f123ee8

File tree

Expand file treeCollapse file tree

1 file changed

+18
-7
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-7
lines changed

‎examples/axes_grid1/simple_axes_divider1.py

Copy file name to clipboardExpand all lines: examples/axes_grid1/simple_axes_divider1.py
+18-7Lines 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 setup(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+
setup(ax1, "nx=0, ny=0")
2736
ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2))
37+
setup(ax2, "nx=0, ny=2")
2838
ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2))
39+
setup(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+
setup(ax4, "nx=2, nx1=4, ny=0")
3342

3443
##############################################################################
3544
# Axes sizes that scale with the figure size; fixed paddings.
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+
setup(ax1, "nx=0, ny=0")
4859
ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2))
60+
setup(ax2, "nx=0, ny=2")
4961
ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2))
62+
setup(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+
setup(ax4, "nx=2, nx1=4, ny=0")
5465

5566
plt.show()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.