Skip to content

Commit 80d473e

Browse files
authored
Merge pull request #5137 from plotly/add-colors
Add supported CSS colors page
2 parents e7a4bb7 + c8b38f4 commit 80d473e

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

Diff for: doc/python/supported-colors.md

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
---
2+
jupyter:
3+
jupytext:
4+
notebook_metadata_filter: all
5+
text_representation:
6+
extension: .md
7+
format_name: markdown
8+
format_version: '1.3'
9+
jupytext_version: 1.17.0
10+
kernelspec:
11+
display_name: Python 3 (ipykernel)
12+
language: python
13+
name: python3
14+
language_info:
15+
codemirror_mode:
16+
name: ipython
17+
version: 3
18+
file_extension: .py
19+
mimetype: text/x-python
20+
name: python
21+
nbconvert_exporter: python
22+
pygments_lexer: ipython3
23+
version: 3.13.2
24+
plotly:
25+
description: A list of supported named CSS Colors
26+
display_as: file_settings
27+
language: python
28+
layout: base
29+
name: Supported CSS Colors
30+
order: 40
31+
page_type: example_index
32+
permalink: python/css-colors/
33+
thumbnail: thumbnail/shape.jpg
34+
---
35+
36+
# Supported CSS Colors
37+
38+
Many properties in Plotly.py for configuring colors support named CSS colors. For example, marker colors:
39+
40+
```python
41+
import plotly.graph_objects as go
42+
43+
fig = go.Figure([
44+
go.Bar(
45+
x=['Jan', 'Feb', 'Mar', 'Apr'],
46+
y=[20, 14, 25, 16],
47+
name='Primary Product',
48+
# Named CSS color
49+
marker_color='royalblue'
50+
)
51+
])
52+
53+
fig.show()
54+
```
55+
56+
These colors are supported in Plotly.py when a property accepts a [named CSS color](https://developer.mozilla.org/en-US/docs/Web/CSS/named-color).
57+
58+
```python hide_code=true
59+
import plotly.graph_objects as go
60+
import pandas as pd
61+
62+
supported_colors = ["aliceblue", "antiquewhite", "aqua", "aquamarine", "azure",
63+
"beige", "bisque", "black", "blanchedalmond", "blue",
64+
"blueviolet", "brown", "burlywood", "cadetblue",
65+
"chartreuse", "chocolate", "coral", "cornflowerblue",
66+
"cornsilk", "crimson", "cyan", "darkblue", "darkcyan",
67+
"darkgoldenrod", "darkgray", "darkgrey", "darkgreen",
68+
"darkkhaki", "darkmagenta", "darkolivegreen", "darkorange",
69+
"darkorchid", "darkred", "darksalmon", "darkseagreen",
70+
"darkslateblue", "darkslategray", "darkslategrey",
71+
"darkturquoise", "darkviolet", "deeppink", "deepskyblue",
72+
"dimgray", "dimgrey", "dodgerblue", "firebrick",
73+
"floralwhite", "forestgreen", "fuchsia", "gainsboro",
74+
"ghostwhite", "gold", "goldenrod", "gray", "grey", "green",
75+
"greenyellow", "honeydew", "hotpink", "indianred", "indigo",
76+
"ivory", "khaki", "lavender", "lavenderblush", "lawngreen",
77+
"lemonchiffon", "lightblue", "lightcoral", "lightcyan",
78+
"lightgoldenrodyellow", "lightgray", "lightgrey",
79+
"lightgreen", "lightpink", "lightsalmon", "lightseagreen",
80+
"lightskyblue", "lightslategray", "lightslategrey",
81+
"lightsteelblue", "lightyellow", "lime", "limegreen",
82+
"linen", "magenta", "maroon", "mediumaquamarine",
83+
"mediumblue", "mediumorchid", "mediumpurple",
84+
"mediumseagreen", "mediumslateblue", "mediumspringgreen",
85+
"mediumturquoise", "mediumvioletred", "midnightblue",
86+
"mintcream", "mistyrose", "moccasin", "navajowhite", "navy",
87+
"oldlace", "olive", "olivedrab", "orange", "orangered",
88+
"orchid", "palegoldenrod", "palegreen", "paleturquoise",
89+
"palevioletred", "papayawhip", "peachpuff", "peru", "pink",
90+
"plum", "powderblue", "purple", "red", "rosybrown",
91+
"royalblue", "rebeccapurple", "saddlebrown", "salmon",
92+
"sandybrown", "seagreen", "seashell", "sienna", "silver",
93+
"skyblue", "slateblue", "slategray", "slategrey", "snow",
94+
"springgreen", "steelblue", "tan", "teal", "thistle", "tomato",
95+
"turquoise", "violet", "wheat", "white", "whitesmoke",
96+
"yellow", "yellowgreen"]
97+
98+
fig = go.Figure(layout=dict(title="Supported Named CSS Colors"))
99+
100+
for i, color in enumerate(supported_colors):
101+
row, col = i // 5, i % 5
102+
x0, y0 = col * 1.2, -row * 1.2
103+
104+
fig.add_shape(
105+
type="rect",
106+
x0=x0, y0=y0,
107+
x1=x0+1, y1=y0+1,
108+
fillcolor=color,
109+
line=dict(color="black", width=0.2),
110+
)
111+
112+
fig.add_annotation(
113+
x=x0+0.5, y=y0-0.1,
114+
text=color,
115+
showarrow=False,
116+
font=dict(size=10)
117+
)
118+
119+
fig.update_layout(
120+
height=((len(supported_colors) // 5) + (1 if len(supported_colors) % 5 else 0)) * 120,
121+
width=800,
122+
showlegend=False,
123+
plot_bgcolor='rgba(0,0,0,0)',
124+
margin=dict(l=50, r=50, t=50, b=50),
125+
xaxis=dict(
126+
showgrid=False,
127+
zeroline=False,
128+
showticklabels=False,
129+
range=[-0.5, 6]
130+
),
131+
yaxis=dict(
132+
showgrid=False,
133+
zeroline=False,
134+
showticklabels=False,
135+
scaleanchor="x",
136+
scaleratio=1,
137+
range=[-((len(supported_colors) // 5) + 1) * 1.2, 1.5]
138+
)
139+
)
140+
141+
fig.show()
142+
```

0 commit comments

Comments
 (0)