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

Commitae1359e

Browse files
committed
DOC: add color sequences reference example [ci doc]
1 parent46ea8f0 commitae1359e

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""
2+
=====================
3+
Named Color Sequences
4+
=====================
5+
6+
Matplotlib's `~matplotlib.colors.ColorSequenceRegistry` allows access to
7+
predefined lists of colors by name e.g.
8+
``colors = matplotlib.color_sequences['Set1']``. This example shows all of the
9+
built in color sequences.
10+
11+
Note that user-defined sequences can be added via the registry's
12+
`~matplotlib.colors.ColorSequenceRegistry.register` method.
13+
"""
14+
15+
importmatplotlib.pyplotasplt
16+
importnumpyasnp
17+
18+
importmatplotlibasmpl
19+
20+
21+
defplot_color_sequences(names,ax):
22+
# Display each named color sequence horizontally on the supplied axes.
23+
24+
forn,nameinenumerate(names):
25+
colors=mpl.color_sequences[name]
26+
n_colors=len(colors)
27+
x=np.arange(n_colors)
28+
y=np.full_like(x,n)
29+
30+
ax.scatter(x,y,facecolor=colors,edgecolor='dimgray',s=200,zorder=2)
31+
32+
ax.set_yticks(range(len(names)),labels=names)
33+
ax.grid(visible=True,axis='y')
34+
ax.yaxis.set_inverted(True)
35+
ax.xaxis.set_visible(False)
36+
ax.spines[:].set_visible(False)
37+
ax.tick_params(left=False)
38+
39+
40+
built_in_color_sequences= [
41+
'tab10','tab20','tab20b','tab20c','Pastel1','Pastel2','Paired',
42+
'Accent','Dark2','Set1','Set2','Set3','petroff10']
43+
44+
45+
fig,ax=plt.subplots(figsize=(6.4,9.6),layout='constrained')
46+
47+
plot_color_sequences(built_in_color_sequences,ax)
48+
ax.set_title('Built In Color Sequences')
49+
50+
plt.show()
51+
52+
53+
# %%
54+
#
55+
# .. admonition:: References
56+
#
57+
# The use of the following functions, methods, classes and modules is shown
58+
# in this example:
59+
#
60+
# - `matplotlib.colors.ColorSequenceRegistry`
61+
# - `matplotlib.axes.Axes.scatter`
62+
#
63+
# .. tags::
64+
#
65+
# styling: color
66+
# purpose: reference

‎galleries/examples/color/individual_colors_from_cmap.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
# Extracting colors from a discrete colormap
3939
# ------------------------------------------
4040
# The list of all colors in a `.ListedColormap` is available as the ``colors``
41-
# attribute.
41+
# attribute. Note that all the colors from Matplotlib's qualitative color maps
42+
# are also available as color sequences, so may be accessed more directly from
43+
# the color sequence registry. See :doc:`/gallery/color/color_sequences`.
4244

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

‎lib/matplotlib/colors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class ColorSequenceRegistry(Mapping):
108108
import matplotlib as mpl
109109
colors = mpl.color_sequences['tab10']
110110
111+
For a list of built in color sequences, see :doc:`/gallery/color/color_sequences`.
111112
The returned lists are copies, so that their modification does not change
112113
the global definition of the color sequence.
113114

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp