Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3d0fbaf

Browse files
committed
ValueError exception added to handle mix of {} and % string
1 parent 6ba7d5f commit 3d0fbaf

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/matplotlib/colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
404404
try:
405405
self._formatter = ticker.FormatStrFormatter(format)
406406
_ = self._formatter(0)
407-
except TypeError:
407+
except (TypeError, ValueError):
408408
self._formatter = ticker.StrMethodFormatter(format)
409409
else:
410410
self._formatter = format # Assume it is a Formatter or None

lib/matplotlib/tests/test_colorbar.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,3 +1230,8 @@ def test_colorbar_wrong_figure():
12301230
fig_tl.colorbar(im)
12311231
fig_tl.draw_without_rendering()
12321232
fig_cl.draw_without_rendering()
1233+
1234+
1235+
def test_colorbar_format_string_and_old():
1236+
plt.imshow([[0, 1]])
1237+
plt.colorbar(format="{x}%")

0 commit comments

Comments
 (0)