|
11 | 11 | BoundaryNorm, LogNorm, PowerNorm, Normalize, NoNorm
|
12 | 12 | )
|
13 | 13 | from matplotlib.colorbar import Colorbar
|
14 |
| -from matplotlib.ticker import FixedLocator |
| 14 | +from matplotlib.ticker import FixedLocator, LogFormatter |
15 | 15 | from matplotlib.testing.decorators import check_figures_equal
|
16 | 16 |
|
17 | 17 |
|
@@ -950,3 +950,32 @@ def test_colorbar_no_warning_rcparams_grid_true():
|
950 | 950 | im = ax.pcolormesh([0, 1], [0, 1], [[1]])
|
951 | 951 | # make sure that no warning is raised by fig.colorbar
|
952 | 952 | fig.colorbar(im)
|
| 953 | + |
| 954 | + |
| 955 | +def test_colorbar_set_formatter_locator(): |
| 956 | + # check that the locator properties echo what is on the axis: |
| 957 | + fig, ax = plt.subplots() |
| 958 | + pc = ax.pcolormesh(np.random.randn(10, 10)) |
| 959 | + cb = fig.colorbar(pc) |
| 960 | + cb.ax.yaxis.set_major_locator(FixedLocator(np.arange(10))) |
| 961 | + cb.ax.yaxis.set_minor_locator(FixedLocator(np.arange(0, 10, 0.2))) |
| 962 | + assert cb.locator == cb.ax.yaxis.get_major_locator() |
| 963 | + assert cb.minorlocator == cb.ax.yaxis.get_minor_locator() |
| 964 | + cb.ax.yaxis.set_major_formatter(LogFormatter()) |
| 965 | + cb.ax.yaxis.set_minor_formatter(LogFormatter()) |
| 966 | + assert cb.formatter == cb.ax.yaxis.get_major_formatter() |
| 967 | + assert cb.minorformatter == cb.ax.yaxis.get_minor_formatter() |
| 968 | + |
| 969 | + # check that the setter works as expected: |
| 970 | + loc = FixedLocator(np.arange(7)) |
| 971 | + cb.locator = loc |
| 972 | + assert cb.ax.yaxis.get_major_locator() == loc |
| 973 | + loc = FixedLocator(np.arange(0, 7, 0.1)) |
| 974 | + cb.minorlocator = loc |
| 975 | + assert cb.ax.yaxis.get_minor_locator() == loc |
| 976 | + fmt = LogFormatter() |
| 977 | + cb.formatter = fmt |
| 978 | + assert cb.ax.yaxis.get_major_formatter() == fmt |
| 979 | + fmt = LogFormatter() |
| 980 | + cb.minorformatter = fmt |
| 981 | + assert cb.ax.yaxis.get_minor_formatter() == fmt |
0 commit comments