Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7f63a18

Browse files
authored
Merge pull request#27015 from borgesaugusto/iss_27007
ValueError exception added to handle mix of {} and % string in colorbar format
2 parentscfe5bf7 +10b4157 commit7f63a18

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
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-
exceptTypeError:
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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
BoundaryNorm,LogNorm,PowerNorm,Normalize,NoNorm
1616
)
1717
frommatplotlib.colorbarimportColorbar
18-
frommatplotlib.tickerimportFixedLocator,LogFormatter
18+
frommatplotlib.tickerimportFixedLocator,LogFormatter,StrMethodFormatter
1919
frommatplotlib.testing.decoratorsimportcheck_figures_equal
2020

2121

@@ -1230,3 +1230,9 @@ 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+
deftest_colorbar_format_string_and_old():
1236+
plt.imshow([[0,1]])
1237+
cb=plt.colorbar(format="{x}%")
1238+
assertisinstance(cb._formatter,StrMethodFormatter)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp