In Plotly Express, set category colors with color_discrete_map={"Category": "#hex"} to choose each one, or color_discrete_sequence=px.colors.qualitative.Safe to switch the whole palette. For numeric colors, use color_continuous_scale="Viridis". With graph_objects, set marker_color= or line_color= on the trace. The examples use Plotly 6.9 and also run on Plotly 7.
Quick Example
import numpy as np
import pandas as pd
import plotly.express as px
rng = np.random.default_rng(12)
weeks = pd.date_range("2026-01-05", periods=20, freq="W-MON")
installs = pd.DataFrame({
"week": np.tile(weeks, 3),
"platform": np.repeat(["iOS", "Android", "Web"], 20),
"installs": np.concatenate([
3200 + 40 * np.arange(20) + rng.normal(0, 150, 20),
4100 + 90 * np.arange(20) + rng.normal(0, 200, 20),
1500 - 20 * np.arange(20) + rng.normal(0, 120, 20),
]).round(),
})
fig = px.line(
installs, x="week", y="installs", color="platform",
color_discrete_map={"iOS": "#1d4ed8", "Android": "#16a34a", "Web": "#9ca3af"},
labels={"week": "", "installs": "Weekly installs", "platform": "Platform"},
title="App installs by platform",
)
fig.update_traces(line_width=3)
fig.show()
The dictionary keys are the values in the platform column, so each platform keeps its color however the data is sorted or filtered. Gray for Web pushes it into the background, which suits a chart about the two app stores. Colors can be hex codes, CSS names ("steelblue"), or rgb()/rgba() strings.
Built-in color palettes for categories
px.colors.qualitative holds Plotly's palettes for categories. Each is a plain list of color strings, and swatches() draws them all:
fig = px.colors.qualitative.swatches()
fig.update_layout(width=800, height=900)
fig.show()

Plotly is the default. Safe is designed to stay distinguishable for colorblind readers, Dark24 and Light24 have 24 colors for many categories, and Set2 and Pastel are softer. Add _r to reverse any of them (px.colors.qualitative.Set2_r).
color_discrete_sequence vs color_discrete_map
color_discrete_sequence= hands out colors in order: the first category gets the first color, and so on. color_discrete_map= names the color for each category. Here are the same bars both ways:
sales = pd.DataFrame({
"region": ["North", "South", "East", "West", "Central"],
"revenue": [4.2, 3.1, 5.6, 2.7, 3.8],
})
fig = px.bar(sales, x="region", y="revenue", color="region",
color_discrete_sequence=px.colors.qualitative.Safe,
labels={"revenue": "Revenue ($M)", "region": ""},
title="color_discrete_sequence=px.colors.qualitative.Safe",
width=700, height=380)
fig.update_layout(showlegend=False)
fig.show()
highlight = {region: "#cbd5e1" for region in sales["region"]}
highlight["East"] = "#ea580c"
fig = px.bar(sales, x="region", y="revenue", color="region",
color_discrete_map=highlight,
labels={"revenue": "Revenue ($M)", "region": ""},
title="color_discrete_map: East highlighted",
width=700, height=380)
fig.update_layout(showlegend=False)
fig.show()


| Use | When |
|---|---|
color_discrete_sequence= |
You want a different palette and don't mind which category gets which color |
color_discrete_map= |
A category must always have the same color (brands, parties, "Other" in gray), or you're highlighting one |
color_discrete_map="identity" |
The column already holds color strings, such as a "color" column you built |
color_discrete_sequence=["#0f766e"] |
One color for every bar or line, without color= |
A sequence follows the order of the data, so filtering out one category shifts every color after it. When the same categories appear in several charts, a map keeps them consistent.
Continuous colorscales for numbers
When color= is numeric, Plotly uses a continuous scale. color_continuous_scale= takes a scale name, range_color= fixes the ends, and for values above and below a center point, color_continuous_midpoint= centers a diverging scale:
months = pd.period_range("2025-01", periods=24, freq="M").strftime("%b %Y")
anomaly = np.round(0.4 * np.sin(np.arange(24) / 3) + rng.normal(0, 0.35, 24), 2)
temps = pd.DataFrame({"month": months, "anomaly": anomaly})
fig = px.bar(temps, x="month", y="anomaly", color="anomaly",
color_continuous_scale="RdBu_r", color_continuous_midpoint=0,
labels={"anomaly": "°C vs normal", "month": ""},
title="Monthly temperature anomaly", width=900, height=420)
fig.update_xaxes(tickangle=-45)
fig.show()

With color_continuous_midpoint=0, zero is always the white center of the scale, even when the data runs further above zero than below it (here from -0.61 to +0.67). The _r suffix reverses a scale, which puts red on the warm side here.
Scales come in three families:
| Family | Module | Examples | For |
|---|---|---|---|
| Sequential | px.colors.sequential |
"Viridis", "Blues", "Plasma", "YlOrRd" |
Low to high (counts, prices) |
| Diverging | px.colors.diverging |
"RdBu", "PiYG", "Tealrose" |
Above and below a center (change, anomalies) |
| Cyclical | px.colors.cyclical |
"Twilight", "IceFire", "Phase" |
Values that wrap around (hours, angles, months) |
px.colors.named_colorscales() lists all 94 names, and px.colors.sequential.swatches_continuous() draws the sequential scales as gradients. Names are case-insensitive. A misspelled name raises ValueError: Invalid value of type 'builtins.str' received for the 'colorscale' property.
Make your own colorscale
Pass a list of colors to spread them evenly, or [position, color] pairs to place them:
grid = pd.DataFrame(rng.gamma(2, 15, (6, 10)).round(),
index=["Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
columns=[f"{h}:00" for h in range(9, 19)])
fig = px.imshow(
grid, text_auto=True, aspect="auto",
color_continuous_scale=[[0, "#f8fafc"], [0.5, "#5eead4"], [1, "#134e4a"]],
labels={"color": "Visitors"}, title="Visitors by day and hour",
width=800, height=380,
)
fig.show()

The first position must be 0 and the last 1. To go the other way and pick a few discrete colors from a continuous scale, use px.colors.sample_colorscale("Viridis", 5), which returns five rgb() strings you can pass to color_discrete_sequence=. The heatmap post has more on px.imshow.
Set colors with graph_objects
With go traces, color is a trace property. A single value colors the whole trace, and a list colors each point or bar:
import plotly.graph_objects as go
colors = ["#ea580c" if value == sales["revenue"].max() else "#94a3b8"
for value in sales["revenue"]]
fig = go.Figure(go.Bar(x=sales["region"], y=sales["revenue"], marker_color=colors,
marker_line=dict(color="#334155", width=1)))
fig.add_trace(go.Scatter(x=sales["region"], y=[sales["revenue"].mean()] * 5,
mode="lines", line=dict(color="#0f172a", dash="dash"),
name="Average"))
fig.update_layout(title="Highest region in orange", showlegend=False,
width=700, height=380)
fig.show()

| Trace | Property |
|---|---|
go.Bar, go.Scatter markers |
marker_color= (one color, a list, or numbers with marker_colorscale=) |
go.Scatter lines |
line_color= |
| Bar and marker outlines | marker_line_color=, marker_line_width= |
| Filled areas | fillcolor= |
go.Heatmap, go.Surface |
colorscale=, plus zmid= to center it |
To change a Plotly Express figure after it's made, the same properties work through fig.update_traces(marker_color="#0f766e"), or with selector=dict(name="Web") to change one trace.
Set a default palette for every chart
To use one palette in every figure of a notebook or app, set it once instead of passing it to each call:
import plotly.io as pio
px.defaults.color_discrete_sequence = px.colors.qualitative.Safe # Plotly Express only
px.defaults.color_continuous_scale = "Viridis"
pio.templates["brand"] = go.layout.Template(pio.templates["plotly_white"])
pio.templates["brand"].layout.colorway = ["#1d4ed8", "#16a34a", "#ea580c", "#9333ea"]
pio.templates.default = "brand" # also applies to graph_objects figures
pio.templates.default = "plotly" # back to the default
px.defaults.color_discrete_sequence = None
px.defaults.color_continuous_scale = None
px.defaults only changes Plotly Express. A template's colorway is the list every trace draws from when it has no color of its own, so it covers go figures too. Plotly templates and themes covers building a full theme.
Common problems
| Problem | Cause | Fix |
|---|---|---|
color_discrete_sequence is ignored |
The color column is numeric, so Plotly uses a continuous scale |
color=df["col"].astype(str), or use color_continuous_scale= |
| Colors swap between charts | A sequence follows the order of the data | Use color_discrete_map= |
A category in color_discrete_map is missing |
The key doesn't match the column value exactly | Check spelling and case; unmatched categories fall back to the sequence |
Invalid value ... for the 'colorscale' property |
Misspelled scale name | Check px.colors.named_colorscales() |
| The diverging scale isn't centered | The data isn't symmetric around the center | color_continuous_midpoint=0 (Plotly Express) or zmid=0 (go.Heatmap) |
| Transparent colors | Plotly takes rgba() strings |
"rgba(29, 78, 216, 0.4)", or opacity=0.4 for the whole trace |
