|
1 | 1 | """
|
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. |
5 | 12 |
|
6 | 13 | """
|
7 | 14 | import matplotlib.pyplot as plt
|
|
11 | 18 | fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[6, 3])
|
12 | 19 |
|
13 | 20 | 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% |
16 | 23 | loc='upper right')
|
17 | 24 |
|
18 | 25 | 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]) |
20 | 27 | axins1.xaxis.set_ticks_position("bottom")
|
21 | 28 |
|
22 | 29 | axins = inset_axes(ax2,
|
23 |
| - width="5%", # width = 10% of parent_bbox width |
| 30 | + width="5%", # width = 5% of parent_bbox width |
24 | 31 | height="50%", # height : 50%
|
25 | 32 | loc='lower left',
|
26 | 33 | bbox_to_anchor=(1.05, 0., 1, 1),
|
|
33 | 40 | # the bbox_to_anchor coordinate.
|
34 | 41 |
|
35 | 42 | 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]) |
37 | 44 |
|
38 | 45 | plt.show()
|
0 commit comments