Skip to content

Commit 5143b57

Browse files
committed
Reword inset axes example.
Merge comment into header text, small relayout/reordering.
1 parent 98115e9 commit 5143b57

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

examples/axes_grid1/demo_colorbar_with_inset_locator.py

+21-24
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,37 @@
66
This example shows how to control the position, height, and width of
77
colorbars using `~mpl_toolkits.axes_grid1.inset_locator.inset_axes`.
88
9-
Controlling the placement of the inset axes is done similarly as that of the
10-
legend: either by providing a location option ("upper right", "best", ...), or
11-
by providing a locator with respect to the parent bbox.
12-
9+
Inset axes placement is controlled as for legends: either by providing a *loc*
10+
option ("upper right", "best", ...), or by providing a locator with respect to
11+
the parent bbox. Parameters such as *bbox_to_anchor* and *borderpad* likewise
12+
work in the same way, and are also demonstrated here.
1313
"""
14-
import matplotlib.pyplot as plt
1514

15+
import matplotlib.pyplot as plt
1616
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
1717

1818
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[6, 3])
1919

20-
axins1 = inset_axes(ax1,
21-
width="50%", # width = 50% of parent_bbox width
22-
height="5%", # height : 5%
23-
loc='upper right')
24-
2520
im1 = ax1.imshow([[1, 2], [2, 3]])
26-
fig.colorbar(im1, cax=axins1, orientation="horizontal", ticks=[1, 2, 3])
21+
axins1 = inset_axes(
22+
ax1,
23+
width="50%", # width: 50% of parent_bbox width
24+
height="5%", # height: 5%
25+
loc="upper right",
26+
)
2727
axins1.xaxis.set_ticks_position("bottom")
28-
29-
axins = inset_axes(ax2,
30-
width="5%", # width = 5% of parent_bbox width
31-
height="50%", # height : 50%
32-
loc='lower left',
33-
bbox_to_anchor=(1.05, 0., 1, 1),
34-
bbox_transform=ax2.transAxes,
35-
borderpad=0,
36-
)
37-
38-
# Controlling the placement of the inset axes is basically same as that
39-
# of the legend. you may want to play with the borderpad value and
40-
# the bbox_to_anchor coordinate.
28+
fig.colorbar(im1, cax=axins1, orientation="horizontal", ticks=[1, 2, 3])
4129

4230
im = ax2.imshow([[1, 2], [2, 3]])
31+
axins = inset_axes(
32+
ax2,
33+
width="5%", # width: 5% of parent_bbox width
34+
height="50%", # height: 50%
35+
loc="lower left",
36+
bbox_to_anchor=(1.05, 0., 1, 1),
37+
bbox_transform=ax2.transAxes,
38+
borderpad=0,
39+
)
4340
fig.colorbar(im, cax=axins, ticks=[1, 2, 3])
4441

4542
plt.show()

0 commit comments

Comments
 (0)