|
3 | 3 | Demo Colorbar with Axes Divider
|
4 | 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 | 12 | """
|
7 | 13 |
|
8 | 14 | import matplotlib.pyplot as plt
|
|
14 | 20 |
|
15 | 21 | im1 = ax1.imshow([[1, 2], [3, 4]])
|
16 | 22 | ax1_divider = make_axes_locatable(ax1)
|
| 23 | +# add an axes to the right of the main axes. |
17 | 24 | cax1 = ax1_divider.append_axes("right", size="7%", pad="2%")
|
18 | 25 | cb1 = colorbar(im1, cax=cax1)
|
19 | 26 |
|
20 | 27 | im2 = ax2.imshow([[1, 2], [3, 4]])
|
21 | 28 | ax2_divider = make_axes_locatable(ax2)
|
| 29 | +# add an axes above the main axes. |
22 | 30 | cax2 = ax2_divider.append_axes("top", size="7%", pad="2%")
|
23 | 31 | cb2 = colorbar(im2, cax=cax2, orientation="horizontal")
|
| 32 | +# change tick position to top. Tick position defaults to bottom and overlaps |
| 33 | +# the image. |
24 | 34 | cax2.xaxis.set_ticks_position("top")
|
25 | 35 |
|
26 | 36 | plt.show()
|
0 commit comments