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

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

Merged
dstansby merged 1 commit intomatplotlib:mainfromrcomer:color-sequence-rcparam
Mar 28, 2025

Conversation

rcomer
Copy link
Member

@rcomerrcomer commentedMar 26, 2025
edited
Loading

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

# 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
Copy link
MemberAuthor

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)

story645 and dstansby reacted with hooray emoji
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}')
Copy link
MemberAuthor

@rcomerrcomerMar 26, 2025
edited
Loading

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.

Copy link
Member

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')

Copy link
MemberAuthor

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 😆

Copy link
Member

@timhoffmtimhoffm left a 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.

rcomer reacted with thumbs up emoji
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}')
Copy link
Member

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')

@rcomerrcomer marked this pull request as draftMarch 27, 2025 12:07
@rcomerrcomerforce-pushed thecolor-sequence-rcparam branch from7fd60fc to2065369CompareMarch 27, 2025 14:55
@rcomerrcomer marked this pull request as ready for reviewMarch 27, 2025 16:10
#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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

😍 such a nice improvement!

rcomer reacted with heart emoji
@dstansbydstansby added this to thev3.11.0 milestoneMar 28, 2025
@dstansbydstansby merged commita1aa994 intomatplotlib:mainMar 28, 2025
40 of 41 checks passed
@rcomerrcomer deleted the color-sequence-rcparam branchMarch 28, 2025 11:01
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@QuLogicQuLogicQuLogic left review comments

@timhoffmtimhoffmtimhoffm approved these changes

@dstansbydstansbydstansby approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.11.0
Development

Successfully merging this pull request may close these issues.

[ENH]: set default color cycle to named color sequence
4 participants
@rcomer@QuLogic@timhoffm@dstansby

[8]ページ先頭

©2009-2025 Movatter.jp