|
1 | 1 | """
|
2 |
| -=============================== |
3 |
| -Demo Colorbar with Axes Divider |
4 |
| -=============================== |
| 2 | +============================ |
| 3 | +Colorbar with `.AxesDivider` |
| 4 | +============================ |
5 | 5 |
|
6 |
| -The make_axes_locatable function (part of the axes_divider module) takes an |
7 |
| -existing axes, creates a divider for it and returns an instance of the |
8 |
| -AxesLocator class. The append_axes method of this AxesLocator can then be used |
9 |
| -to create a new axes on a given side ("top", "right", "bottom", or "left") of |
10 |
| -the original axes. This example uses Axes Divider to add colorbars next to |
11 |
| -axes. |
| 6 | +The `.axes_divider.make_axes_locatable` function takes an existing axes, adds |
| 7 | +it to a new `.AxesDivider` and returns the `.AxesDivider`. The `.append_axes` |
| 8 | +method of the `.AxesDivider` can then be used to create a new axes on a given |
| 9 | +side ("top", "right", "bottom", or "left") of the original axes. This example |
| 10 | +uses `.append_axes` to add colorbars next to axes. |
12 | 11 | """
|
13 | 12 |
|
14 | 13 | import matplotlib.pyplot as plt
|
|
19 | 18 |
|
20 | 19 | im1 = ax1.imshow([[1, 2], [3, 4]])
|
21 | 20 | ax1_divider = make_axes_locatable(ax1)
|
22 |
| -# add an axes to the right of the main axes. |
| 21 | +# Add an axes to the right of the main axes. |
23 | 22 | cax1 = ax1_divider.append_axes("right", size="7%", pad="2%")
|
24 | 23 | cb1 = fig.colorbar(im1, cax=cax1)
|
25 | 24 |
|
26 | 25 | im2 = ax2.imshow([[1, 2], [3, 4]])
|
27 | 26 | ax2_divider = make_axes_locatable(ax2)
|
28 |
| -# add an axes above the main axes. |
| 27 | +# Add an axes above the main axes. |
29 | 28 | cax2 = ax2_divider.append_axes("top", size="7%", pad="2%")
|
30 | 29 | cb2 = fig.colorbar(im2, cax=cax2, orientation="horizontal")
|
31 |
| -# change tick position to top. Tick position defaults to bottom and overlaps |
32 |
| -# the image. |
| 30 | +# Change tick position to top (with the default tick position "bottom", ticks |
| 31 | +# overlap the image). |
33 | 32 | cax2.xaxis.set_ticks_position("top")
|
34 | 33 |
|
35 | 34 | plt.show()
|
0 commit comments