-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add a registry for color sequences #22387
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
Conversation
try: | ||
return list(self._color_sequences[item]) | ||
except KeyError: | ||
raise KeyError(f"{item!r} is not a known color sequence name") |
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.
Should we include the list of known keys here?
So these are essentially colour palettes? Should they be named colour palettes? And if they are colour palettes, how does that jive with colour palettes in seaborn? |
Yes maybe we should hoist the palette framework to matplotlib? Then in the context of this request we could add named_palette to take the name of a sequential colormap? I think it may be confusing for us to have a parallel api to seaborn, so if we go a different way we should be very explicit about the differences. |
seaborn.color_palette() is more a color sequence generator that a registry. That's much more than I had in mind, but we can discuss whether we want that functionality.
Apart from (1) returning some named palettes, it can create a palette:
(5) Additionally, one can choose the number of colors. This is quite nice. (6) Additionally, one can desaturate the colors. This feels a bit much for the function. One could alternatively have a function (7) Additionally, one can turn each of the palettes into a Colormap. |
lib/matplotlib/colors.py
Outdated
""" | ||
Register a new color sequence. | ||
|
||
The colormap registry stores a copy of the given *color_list*, so that |
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.
colormap -> color sequence
Moving to draft until we have decided whether and how far we want to go the seaborn way. Next actions:
|
Talked about this on today's call: https://hackmd.io/jd_7FjxNQ4y7XgNknvmvGQ?view#color-registry The consensus was
|
fef03f9
to
e5d6be8
Compare
The existing PR should comply with everything we discussed in the dev call. Marking as ready-to-review. |
The doc failures are relevant. |
e5d6be8
to
3aeaa2d
Compare
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.
Do we want to have __contains__
to check for registered sequences?
92dd83c
to
3128f0d
Compare
|
Ah, I missed the class inheritance. |
Color sequences are simply lists of colors, that we store by name in a registry. The registry is modelled similar to the ColormapRegistry to 1) support immutable builtin color sequences and 2) to return copies so that one cannot mess with the global definition of the color sequence through an obtained instance. For now, I've made the sequences used for `ListedColormap`s available as builtin sequences, but that's open for discussion. More usage documentation should be added in the color examples and/or tutorials, but I'll wait with that till after the general approval of the structure and API. One common use case will be ``` plt.rc_params['axes.prop_cycle'] = plt.cycler(color=plt.color_sequences['Pastel1') ``` Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Color sequences are simply lists of colors, that we store by name in
a registry. The registry is modelled similar to the ColormapRegistry
to 1) support immutable builtin color sequences and 2) to return copies
so that one cannot mess with the global definition of the color sequence
through an obtained instance.
Note that some details of
ColormapRegistry
are different and we needdifferent docstrings so that it's easier to have a separate class and not try
to factor out some common aspects in a base class.
For now, I've made the sequences used for
ListedColormap
s availableas builtin sequences, but that's open for discussion.
More usage documentation should be added in the color examples and/or
tutorials, but I'll wait with that till after the general approval of
the structure and API. One common use case will be