Supported CSS Colors in Python
A list of supported named CSS Colors
Plotly Studio: Transform any dataset into an interactive data application in minutes with AI. Try Plotly Studio now.
Supported CSS Colors¶
Many properties in Plotly.py for configuring colors support named CSS colors. For example, marker colors:
import plotly.graph_objects as go
fig = go.Figure([
go.Bar(
x=['Jan', 'Feb', 'Mar', 'Apr'],
y=[20, 14, 25, 16],
name='Primary Product',
# Named CSS color
marker_color='royalblue'
)
])
fig.show()
These colors are supported in Plotly.py when a property accepts a named CSS color.
Other Color Formats¶
Changed in 7.0
As well as named colors, color properties accept color strings in the formats defined by the CSS Color 4 specification, including rgb(), rgba(), hsl(), hsla(), hwb(), lab(), lch(), oklab(), oklch(), color(), and hexadecimal notation with a leading #.
Version 7 parses these strings according to that specification. Four formats that earlier versions accepted no longer give the same result. A string that cannot be parsed at all falls back to the property's default:
| No longer works | Example | Use instead |
|---|---|---|
The hsv() color function |
"hsv(200, 80%, 80%)" |
"hsl(200, 67%, 47%)", "hwb()", hexadecimal, or "rgb()" |
| Comma separated saturation and lightness values without percent units | "hsl(0, 100, 40)" |
"hsl(0, 100%, 40%)", or the space separated "hsl(0 100 40)" |
| Channel values given as fractions of 1 | "rgb(0.5, 0.5, 0.5)" (now renders as near black) |
"rgb(128, 128, 128)" |
Hexadecimal values without a leading # |
"fff" |
"#fff" |
These rules apply to color strings only. Numeric arrays used with a colorscale are unaffected.
What About Dash?¶
Dash is an open-source framework for building analytical applications, with no Javascript required, and it is tightly integrated with the Plotly graphing library.
Learn about how to install Dash at https://dash.plot.ly/installation.
Everywhere in this page that you see fig.show(), you can display the same figure in a Dash application by passing it to the figure argument of the Graph component from the built-in dash_core_components package like this:
import plotly.graph_objects as go # or plotly.express as px
fig = go.Figure() # or any Plotly Express function e.g. px.bar(...)
# fig.add_trace( ... )
# fig.update_layout( ... )
from dash import Dash, dcc, html
app = Dash()
app.layout = html.Div([
dcc.Graph(figure=fig)
])
app.run(debug=True, use_reloader=False) # Turn off reloader if inside Jupyter