8000 TST: test setters and getters in colorbar · matplotlib/matplotlib@b65ec3c · GitHub
[go: up one dir, main page]

Skip to content

Commit b65ec3c

Browse files
committed
TST: test setters and getters in colorbar
1 parent 01d7288 commit b65ec3c

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lib/matplotlib/colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ def minorformatter(self, fmt):
567567
"""
568568
Set minor formatter being used for colorbar
569569
"""
570-
self._long_axis().set_minor_locator(fmt)
570+
self._long_axis().set_minor_formatter(fmt)
571571
self._minorformatter = fmt
572572

573573
def _cbar_cla(self):

lib/matplotlib/tests/test_colorbar.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
BoundaryNorm, LogNorm, PowerNorm, Normalize, NoNorm
1212
)
1313
from matplotlib.colorbar import Colorbar
14-
from matplotlib.ticker import FixedLocator
14+
from matplotlib.ticker import FixedLocator, LogFormatter
1515
from matplotlib.testing.decorators import check_figures_equal
1616

1717

@@ -950,3 +950,32 @@ def test_colorbar_no_warning_rcparams_grid_true():
950950
im = ax.pcolormesh([0, 1], [0, 1], [[1]])
951951
# make sure that no warning is raised by fig.colorbar
952952
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

Comments
 (0)
0