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

Skip to content

Commit 30282cf

Browse files
authored
Merge pull request #16775 from anntzer/sal
Cleanup axes_divider examples.
2 parents 9d40170 + f5abdda commit 30282cf

File tree

4 files changed

+52
-66
lines changed

4 files changed

+52
-66
lines changed

examples/axes_grid1/demo_fixed_size_axes.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
====================
33
Demo Fixed Size Axes
44
====================
5-
65
"""
6+
77
import matplotlib.pyplot as plt
88

99
from mpl_toolkits.axes_grid1 import Divider, Size
10-
from mpl_toolkits.axes_grid1.mpl_axes import Axes
1110

1211
###############################################################################
1312

@@ -19,13 +18,11 @@
1918
h = [Size.Fixed(1.0), Size.Fixed(4.5)]
2019
v = [Size.Fixed(0.7), Size.Fixed(5.)]
2120

22-
divider = Divider(fig, (0.0, 0.0, 1., 1.), h, v, aspect=False)
23-
# the width and height of the rectangle is ignored.
24-
25-
ax = Axes(fig, divider.get_position())
26-
ax.set_axes_locator(divider.new_locator(nx=1, ny=1))
21+
divider = Divider(fig, (0, 0, 1, 1), h, v, aspect=False)
22+
# The width and height of the rectangle are ignored.
2723

28-
fig.add_axes(ax)
24+
ax = fig.add_axes(divider.get_position(),
25+
axes_locator=divider.new_locator(nx=1, ny=1))
2926

3027
ax.plot([1, 2, 3])
3128

@@ -39,12 +36,12 @@
3936
h = [Size.Fixed(1.0), Size.Scaled(1.), Size.Fixed(.2)]
4037
v = [Size.Fixed(0.7), Size.Scaled(1.), Size.Fixed(.5)]
4138

42-
divider = Divider(fig, (0.0, 0.0, 1., 1.), h, v, aspect=False)
43-
# the width and height of the rectangle is ignored.
39+
divider = Divider(fig, (0, 0, 1, 1), h, v, aspect=False)
40+
# The width and height of the rectangle are ignored.
4441

45-
ax = Axes(fig, divider.get_position())
46-
ax.set_axes_locator(divider.new_locator(nx=1, ny=1))
47-
48-
fig.add_axes(ax)
42+
ax = fig.add_axes(divider.get_position(),
43+
axes_locator=divider.new_locator(nx=1, ny=1))
4944

5045
ax.plot([1, 2, 3])
46+
47+
plt.show()

examples/axes_grid1/simple_axes_divider1.py

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,52 @@
44
=====================
55
66
"""
7+
78
from mpl_toolkits.axes_grid1 import Size, Divider
89
import matplotlib.pyplot as plt
910

1011

11-
fig1 = plt.figure(1, (6, 6))
12+
##############################################################################
13+
# Fixed axes sizes; fixed paddings.
14+
15+
fig = plt.figure(figsize=(6, 6))
1216

13-
# fixed size in inch
14-
horiz = [Size.Fixed(1.), Size.Fixed(.5), Size.Fixed(1.5),
15-
Size.Fixed(.5)]
17+
# Sizes are in inches.
18+
horiz = [Size.Fixed(1.), Size.Fixed(.5), Size.Fixed(1.5), Size.Fixed(.5)]
1619
vert = [Size.Fixed(1.5), Size.Fixed(.5), Size.Fixed(1.)]
1720

1821
rect = (0.1, 0.1, 0.8, 0.8)
19-
# divide the axes rectangle into grid whose size is specified by horiz * vert
20-
divider = Divider(fig1, rect, horiz, vert, aspect=False)
21-
22-
# the rect parameter will be ignore as we will set axes_locator
23-
ax1 = fig1.add_axes(rect, label="1")
24-
ax2 = fig1.add_axes(rect, label="2")
25-
ax3 = fig1.add_axes(rect, label="3")
26-
ax4 = fig1.add_axes(rect, label="4")
27-
28-
ax1.set_axes_locator(divider.new_locator(nx=0, ny=0))
29-
ax2.set_axes_locator(divider.new_locator(nx=0, ny=2))
30-
ax3.set_axes_locator(divider.new_locator(nx=2, ny=2))
31-
ax4.set_axes_locator(divider.new_locator(nx=2, nx1=4, ny=0))
22+
# Divide the axes rectangle into a grid with sizes specified by horiz * vert.
23+
divider = Divider(fig, rect, horiz, vert, aspect=False)
24+
25+
# The rect parameter will actually be ignored and overridden by axes_locator.
26+
ax1 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=0))
27+
ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2))
28+
ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2))
29+
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)
33+
34+
##############################################################################
35+
# Axes sizes that scale with the figure size; fixed paddings.
36+
37+
fig = plt.figure(figsize=(6, 6))
38+
39+
horiz = [Size.Scaled(1.5), Size.Fixed(.5), Size.Scaled(1.), Size.Scaled(.5)]
40+
vert = [Size.Scaled(1.), Size.Fixed(.5), Size.Scaled(1.5)]
41+
42+
rect = (0.1, 0.1, 0.8, 0.8)
43+
# Divide the axes rectangle into a grid with sizes specified by horiz * vert.
44+
divider = Divider(fig, rect, horiz, vert, aspect=False)
45+
46+
# The rect parameter will actually be ignored and overridden by axes_locator.
47+
ax1 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=0))
48+
ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2))
49+
ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2))
50+
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)
3254

3355
plt.show()

examples/axes_grid1/simple_axes_divider2.py

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

tutorials/toolkits/axes_grid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@
392392
393393
See the example,
394394
395-
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_axes_divider2_001.png
396-
:target: ../../gallery/axes_grid1/simple_axes_divider2.html
395+
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_axes_divider1_002.png
396+
:target: ../../gallery/axes_grid1/simple_axes_divider1.html
397397
:align: center
398398
:scale: 50
399399

0 commit comments

Comments
 (0)