New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: rcParams['legend.loc'] can't use float-tuple like kwarg legend(loc...) #22338
Comments
Also having this issue |
As a general comment, including the full traceback, not just the final line makes these much easier to read In [2]: plt.rcParams['legend.loc'] = (0.9, .7)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In [2], line 1
----> 1 plt.rcParams['legend.loc'] = (0.9, .7)
File /usr/lib/python3.10/site-packages/matplotlib/__init__.py:649, in RcParams.__setitem__(self, key, val)
647 return
648 try:
--> 649 cval = self.validate[key](val)
650 except ValueError as ve:
651 raise ValueError(f"Key {key}: {ve}") from None
File /usr/lib/python3.10/site-packages/matplotlib/rcsetup.py:72, in ValidateInStrings.__call__(self, s)
69 _api.warn_deprecated(
70 self._deprecated_since, name=name, obj_type="function")
71 if self.ignorecase:
---> 72 s = s.lower()
73 if s in self.valid:
74 return self.valid[s]
AttributeError: 'tuple' object has no attribute 'lower' The error is coming out of the validators in rcsetup, not the legend call. I agree there are two things to do here. The first should be done no matter what, but I am a bit wary of the second.
They probably should be done in two PRs. The first only requries the changes at a test, the second will require the changes, a test, an API change note, and a bit of lobbying as to why we really should make this change. |
Partially closes - matplotlib#22338
Partially closes - matplotlib#22338
Partially closes - matplotlib#22338
Hi all, is it still open? |
Yes, the original issue is still not solved. Be aware that the test added in #24600 should be modified as part of it (as that test is to make sure that a somewhat sensible error message is fed with a tuple). |
Thanks, I'll start working on it. |
Bug summary
We can now use a (x,y) argument for
plt.legend(loc=(x,y))
,but using the tuple as a value for rcParams['legend.loc'] fails.
Code for reproduction
Actual outcome
Setting rcParams['legend.loc'] to a tuple fails with
setting rcParams['legend.loc'] to the string representation of a tuple fails with a list of supported values.
Expected outcome
Ideally rcParams['legend.loc'] would apply a tuple the same way the kwarg does.
Second best would be a bit more documentation; 1) reporting the list of supported strings for any un-interpretable value, and 2) mentioning in the default matplotlibrc that only a set of strings are supported.
Additional information
I believe the
loc
kwarg originally only took string values, but that seems to have been at least a major version ago.Operating system
Ubuntu
Matplotlib Version
3.3.4
Matplotlib Backend
TkAgg
Python version
Python 3.9.7
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: