Skip to content

Commit bf464c3

Browse files
NelleVdstansby
authored andcommitted
DOC Better description of inset locator and colorbar (#13272)
* DOC Better description of inset locator and colorbar * Update examples/axes_grid1/demo_colorbar_with_inset_locator.py Co-Authored-By: NelleV <nelle.varoquaux@gmail.com> * DOC Nitpick on title
1 parent 4a85eb5 commit bf464c3

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
"""
2-
================================
3-
Demo Colorbar With Inset Locator
4-
================================
2+
==============================================================
3+
Controlling the position and size of colorbars with Inset Axes
4+
==============================================================
5+
6+
This example shows how to control the position, height, and width of
7+
colorbars using `~mpl_toolkits.axes_grid1.inset_axes`.
8+
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.
512
613
"""
714
import matplotlib.pyplot as plt
@@ -11,16 +18,16 @@
1118
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[6, 3])
1219

1320
axins1 = inset_axes(ax1,
14-
width="50%", # width = 10% of parent_bbox width
15-
height="5%", # height : 50%
21+
width="50%", # width = 50% of parent_bbox width
22+
height="5%", # height : 5%
1623
loc='upper right')
1724

1825
im1 = ax1.imshow([[1, 2], [2, 3]])
19-
plt.colorbar(im1, cax=axins1, orientation="horizontal", ticks=[1, 2, 3])
26+
fig.colorbar(im1, cax=axins1, orientation="horizontal", ticks=[1, 2, 3])
2027
axins1.xaxis.set_ticks_position("bottom")
2128

2229
axins = inset_axes(ax2,
23-
width="5%", # width = 10% of parent_bbox width
30+
width="5%", # width = 5% of parent_bbox width
2431
height="50%", # height : 50%
2532
loc='lower left',
2633
bbox_to_anchor=(1.05, 0., 1, 1),
@@ -33,6 +40,6 @@
3340
# the bbox_to_anchor coordinate.
3441

3542
im = ax2.imshow([[1, 2], [2, 3]])
36-
plt.colorbar(im, cax=axins, ticks=[1, 2, 3])
43+
fig.colorbar(im, cax=axins, ticks=[1, 2, 3])
3744

3845
plt.show()

0 commit comments

Comments
 (0)