There was an error while loading. Please reload this page.
1 parent 6ba7d5f commit 10b4157Copy full SHA for 10b4157
2 files changed
lib/matplotlib/colorbar.py
@@ -404,7 +404,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
404
try:
405
self._formatter = ticker.FormatStrFormatter(format)
406
_ = self._formatter(0)
407
- except TypeError:
+ except (TypeError, ValueError):
408
self._formatter = ticker.StrMethodFormatter(format)
409
else:
410
self._formatter = format # Assume it is a Formatter or None
lib/matplotlib/tests/test_colorbar.py
@@ -15,7 +15,7 @@
15
BoundaryNorm, LogNorm, PowerNorm, Normalize, NoNorm
16
)
17
from matplotlib.colorbar import Colorbar
18
-from matplotlib.ticker import FixedLocator, LogFormatter
+from matplotlib.ticker import FixedLocator, LogFormatter, StrMethodFormatter
19
from matplotlib.testing.decorators import check_figures_equal
20
21
@@ -1230,3 +1230,9 @@ def test_colorbar_wrong_figure():
1230
fig_tl.colorbar(im)
1231
fig_tl.draw_without_rendering()
1232
fig_cl.draw_without_rendering()
1233
+
1234
1235
+def test_colorbar_format_string_and_old():
1236
+ plt.imshow([[0, 1]])
1237
+ cb = plt.colorbar(format="{x}%")
1238
+ assert isinstance(cb._formatter, StrMethodFormatter)
0 commit comments