|
6 | 6 | This example shows how to control the position, height, and width of |
7 | 7 | colorbars using `~mpl_toolkits.axes_grid1.inset_locator.inset_axes`. |
8 | 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. |
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. |
13 | 13 | """ |
14 | | -import matplotlib.pyplot as plt |
15 | 14 |
|
| 15 | +import matplotlib.pyplot as plt |
16 | 16 | from mpl_toolkits.axes_grid1.inset_locator import inset_axes |
17 | 17 |
|
18 | 18 | fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[6, 3]) |
19 | 19 |
|
20 | | -axins1 = inset_axes(ax1, |
21 | | - width="50%", # width = 50% of parent_bbox width |
22 | | - height="5%", # height : 5% |
23 | | - loc='upper right') |
24 | | - |
25 | 20 | 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 | +) |
27 | 27 | 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]) |
41 | 29 |
|
42 | 30 | 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 | +) |
43 | 40 | fig.colorbar(im, cax=axins, ticks=[1, 2, 3]) |
44 | 41 |
|
45 | 42 | plt.show() |
0 commit comments