()
| 916 | |
| 917 | |
| 918 | def test_aspects(): |
| 919 | fig, ax = plt.subplots(3, 2, figsize=(8, 8)) |
| 920 | aspects = [20, 20, 10] |
| 921 | extends = ['neither', 'both', 'both'] |
| 922 | cb = [[None, None, None], [None, None, None]] |
| 923 | for nn, orient in enumerate(['vertical', 'horizontal']): |
| 924 | for mm, (aspect, extend) in enumerate(zip(aspects, extends)): |
| 925 | pc = ax[mm, nn].pcolormesh(np.arange(100).reshape(10, 10)) |
| 926 | cb[nn][mm] = fig.colorbar(pc, ax=ax[mm, nn], orientation=orient, |
| 927 | aspect=aspect, extend=extend) |
| 928 | fig.draw_without_rendering() |
| 929 | # check the extends are right ratio: |
| 930 | np.testing.assert_almost_equal(cb[0][1].ax.get_position().height, |
| 931 | cb[0][0].ax.get_position().height * 0.9, |
| 932 | decimal=2) |
| 933 | # horizontal |
| 934 | np.testing.assert_almost_equal(cb[1][1].ax.get_position().width, |
| 935 | cb[1][0].ax.get_position().width * 0.9, |
| 936 | decimal=2) |
| 937 | # check correct aspect: |
| 938 | pos = cb[0][0].ax.get_position(original=False) |
| 939 | np.testing.assert_almost_equal(pos.height, pos.width * 20, decimal=2) |
| 940 | pos = cb[1][0].ax.get_position(original=False) |
| 941 | np.testing.assert_almost_equal(pos.height * 20, pos.width, decimal=2) |
| 942 | # check twice as wide if aspect is 10 instead of 20 |
| 943 | np.testing.assert_almost_equal( |
| 944 | cb[0][0].ax.get_position(original=False).width * 2, |
| 945 | cb[0][2].ax.get_position(original=False).width, decimal=2) |
| 946 | np.testing.assert_almost_equal( |
| 947 | cb[1][0].ax.get_position(original=False).height * 2, |
| 948 | cb[1][2].ax.get_position(original=False).height, decimal=2) |
| 949 | |
| 950 | |
| 951 | @image_comparison(['proportional_colorbars.png'], remove_text=True, |
nothing calls this directly
no test coverage detected
searching dependent graphs…