Setting rcParams['legend.loc'] to a tuple fails with
AttributeError: 'tuple' object has no attribute 'lower'
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.
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.
the string validator should fail gracefully if value is not a string an tell you what strings are allowed (easy difficulty)
the validator used for 'legend.loc' could be extended to allow sequences of floats as well as strings. Pro is users expect it. The slight risk of this is that if any other clients who are expecting a string out of this value they will be broken, but I think that is a small risk and can be handled with documentation. (medium difficulty)
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.
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).
Activity
alexlenail commented on Nov 14, 2022
Also having this issue
tacaswell commented on Nov 15, 2022
As a general comment, including the full traceback, not just the final line makes these much easier to read
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.
Gracefully fail the string validator for tuple inputs
Gracefully fail the string validator for tuple inputs
Gracefully fail the string validator for tuple inputs
NoyHanan commented on May 5, 2023
Hi all, is it still open?
oscargus commented on May 5, 2023
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).
NoyHanan commented on May 5, 2023
Thanks, I'll start working on it.
matplotlib#22338
matplotlib#22338
matplotlib#22338
matplotlib#22338
Add ability to use float-tuple like kwarg legend(loc...) for rcParams…
Add ability to use float-tuple like kwarg legend(loc...) for rcParams…
Gracefully fail the string validator for tuple inputs
Gracefully fail the string validator for tuple inputs
Gracefully fail the string validator for tuple inputs