Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
ENH: set default color cycle to named color sequence#29808
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
# color cycle for plot lines as list of string color specs: | ||
# single letter, long name, or web-style hex | ||
#axes.prop_cycle: cycler('color', 'tab10') | ||
# color cycle for plot lines as either a named color sequence or a list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
As well as being more succinct, this saves me 40 microseconds 🚀
In [4]:%timeitvalidate_cycler("cycler('color', 'tab10')")80.9μs ±1.25μsperloop (mean ±std.dev.of7runs,10,000loopseach)In [5]:%timeitvalidate_cycler("cycler('color', ['1f77b4', 'ff7f0e', '2ca02c', 'd62728', '9467bd', '8c564b', 'e377c2', '7f7f7f', 'bcbd22', '17becf'])")122μs ±952nsperloop (mean ±std.dev.of7runs,10,000loopseach)
Uh oh!
There was an error while loading.Please reload this page.
lib/matplotlib/rcsetup.py Outdated
colors = [scalar_validator(v.strip()) for v in s if v.strip()] | ||
except ValueError as ve: | ||
ke_msg = str(ke)[1:-1] # strip off quote marks | ||
raise ValueError(f'{ke_msg} and {ve}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'd welcome any feedback on a better way to do the exception handling here. This works to combine the error messages from the two options (see new test) but I feel like I'm missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Can't you simply
raise ValueError(f'{s!r} is neither a color sequence name nor can it be interpreted as a list of colors')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ah, so my problem was trying to be too clever 😆
07a01d9
to846e825
CompareThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I would not bother to discuss the potential ambiguity of color sequence name and single-letter-colors-in-string. AFAIK the potential single letter colors are "rgbcmykw" and it's hard to make reasonable name from that. So I doubt this will ever turn up in practice.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
lib/matplotlib/rcsetup.py Outdated
colors = [scalar_validator(v.strip()) for v in s if v.strip()] | ||
except ValueError as ve: | ||
ke_msg = str(ke)[1:-1] # strip off quote marks | ||
raise ValueError(f'{ke_msg} and {ve}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Can't you simply
raise ValueError(f'{s!r} is neither a color sequence name nor can it be interpreted as a list of colors')
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
7fd60fc
to2065369
Compare#axes.prop_cycle: cycler('color', ['1f77b4', 'ff7f0e', '2ca02c', 'd62728', '9467bd', '8c564b', 'e377c2', '7f7f7f', 'bcbd22', '17becf']) | ||
# color cycle for plot lines as list of string color specs: | ||
# single letter, long name, or web-style hex | ||
#axes.prop_cycle: cycler(color='tab10') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
😍 such a nice improvement!
a1aa994
intomatplotlib:mainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
PR summary
Closes#29799
As mentioned in the issue, it ispossible that someone could register a color sequence called something like "rygbk" and then it would be ambiguous whether to use the color sequence or interpret as single character colors. We agreed that the color sequence would take precedence in this situation. Should I actually document that precedence either in the user guide section or in a next-api-changes note? I think in practice it will come up very rarely if at all.
PR checklist