Bug summary
When the format kwarg passed to colorbar() is a str, colorbar() currently tries to guess whether it is a %-format or a {}-format string, using
if isinstance(format, str):
# Check format between FormatStrFormatter and StrMethodFormatter
try:
self._formatter = ticker.FormatStrFormatter(format)
_ = self._formatter(0)
except TypeError:
self._formatter = ticker.StrMethodFormatter(format)
Even ignoring the (contrieved) case where the format string is valid both as a %-format and a {}-format, there are other failure cases which could be easily handled, specifically format="{x}%" ("I want to format the value with a percent-sign appended to it"): here the _formatter(0) call will fail with a ValueError (which just needs to be caught) rather than a TypeError.
Code for reproduction
Actual outcome
ValueError raised.
Expected outcome
Format string used as expected.
Additional information
Probably just needs additionally catching ValueError, plus a test.
Operating system
No response
Matplotlib Version
3.8
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
from source (.tar.gz)
Bug summary
When the
formatkwarg passed to colorbar() is a str, colorbar() currently tries to guess whether it is a %-format or a {}-format string, usingEven ignoring the (contrieved) case where the format string is valid both as a %-format and a {}-format, there are other failure cases which could be easily handled, specifically
format="{x}%"("I want to format the value with a percent-sign appended to it"): here the _formatter(0) call will fail with a ValueError (which just needs to be caught) rather than a TypeError.Code for reproduction
# see aboveActual outcome
ValueError raised.
Expected outcome
Format string used as expected.
Additional information
Probably just needs additionally catching ValueError, plus a test.
Operating system
No response
Matplotlib Version
3.8
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
from source (.tar.gz)