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

DOC: add color sequences reference example#29563

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
timhoffm merged 1 commit intomatplotlib:mainfromrcomer:doc-color-sequences
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletionsgalleries/examples/color/color_sequences.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
"""
=====================
Named color sequences
=====================

Matplotlib's `~matplotlib.colors.ColorSequenceRegistry` allows access to
predefined lists of colors by name e.g.
``colors = matplotlib.color_sequences['Set1']``. This example shows all of the
built in color sequences.

User-defined sequences can be added via `.ColorSequenceRegistry.register`.
"""

import matplotlib.pyplot as plt
import numpy as np

import matplotlib as mpl


def plot_color_sequences(names, ax):
# Display each named color sequence horizontally on the supplied axes.

for n, name in enumerate(names):
colors = mpl.color_sequences[name]
n_colors = len(colors)
x = np.arange(n_colors)
y = np.full_like(x, n)

ax.scatter(x, y, facecolor=colors, edgecolor='dimgray', s=200, zorder=2)

ax.set_yticks(range(len(names)), labels=names)
ax.grid(visible=True, axis='y')
ax.yaxis.set_inverted(True)
ax.xaxis.set_visible(False)
ax.spines[:].set_visible(False)
ax.tick_params(left=False)


built_in_color_sequences = [
'tab10', 'tab20', 'tab20b', 'tab20c', 'Pastel1', 'Pastel2', 'Paired',
'Accent', 'Dark2', 'Set1', 'Set2', 'Set3', 'petroff10']


fig, ax = plt.subplots(figsize=(6.4, 9.6), layout='constrained')

plot_color_sequences(built_in_color_sequences, ax)
ax.set_title('Built In Color Sequences')

plt.show()


# %%
#
# .. admonition:: References
#
# The use of the following functions, methods, classes and modules is shown
# in this example:
#
# - `matplotlib.colors.ColorSequenceRegistry`
# - `matplotlib.axes.Axes.scatter`
#
# .. tags::
#
# styling: color
# purpose: reference
4 changes: 3 additions & 1 deletiongalleries/examples/color/individual_colors_from_cmap.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,7 +38,9 @@
# Extracting colors from a discrete colormap
# ------------------------------------------
# The list of all colors in a `.ListedColormap` is available as the ``colors``
# attribute.
# attribute. Note that all the colors from Matplotlib's qualitative color maps
# are also available as color sequences, so may be accessed more directly from
# the color sequence registry. See :doc:`/gallery/color/color_sequences`.

colors = mpl.colormaps['Dark2'].colors

Expand Down
1 change: 1 addition & 0 deletionslib/matplotlib/colors.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -108,6 +108,7 @@ class ColorSequenceRegistry(Mapping):
import matplotlib as mpl
colors = mpl.color_sequences['tab10']

For a list of built in color sequences, see :doc:`/gallery/color/color_sequences`.
The returned lists are copies, so that their modification does not change
the global definition of the color sequence.

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp