Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
DOC: update colors from colormaps example#27708
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.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,50 +7,54 @@ | ||
| cycle provides. Selecting individual colors from one of the provided colormaps can be a | ||
| convenient way to do this. | ||
| We can retrieve colors from any `.Colormap` by calling it with a float or a list of | ||
| floats in the range [0, 1]; e.g. ``cmap(0.5)`` will give the middle color. See also | ||
| `.Colormap.__call__`. | ||
| Extracting colors from a continuous colormap | ||
| -------------------------------------------- | ||
| """ | ||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
| import matplotlib as mpl | ||
| n_lines = 21 | ||
| cmap = mpl.colormaps['plasma'] | ||
| # Take colors at regular intervals spanning the colormap. | ||
| colors = cmap(np.linspace(0, 1, n_lines)) | ||
| fig, ax = plt.subplots(layout='constrained') | ||
| for i, colorinenumerate(colors): | ||
| ax.plot([0, i], color=color) | ||
| plt.show() | ||
| # %% | ||
| # | ||
| # Extracting colors from a discrete colormap | ||
| # ------------------------------------------ | ||
| # The list of all colors in a `.ListedColormap` is available as the ``colors`` | ||
| # attribute. | ||
| colors =mpl.colormaps['Dark2'].colors | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. maybe turn that into a section heading to make it more obvious? Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Sectioning: The above should be something "Extracting values from a continuous colormap" (though technically most of the visually continous colormaps are still densely sampled ListedColormaps) and here "Extracting values from a discrete colormap". I also suggest to not combine both the | ||
| fig, ax = plt.subplots(layout='constrained') | ||
| for i, colorinenumerate(colors): | ||
| ax.plot([0, i], color=color) | ||
| plt.show() | ||
| # %% | ||
| # See Also | ||
| # -------- | ||
| # | ||
| # For more details about manipulating colormaps, see :ref:`colormap-manipulation`. To | ||
| # change the default color cycle, see :ref:`color_cycle`. | ||
| # | ||
| # .. admonition:: References | ||
| # | ||