I feel you :)

Actually yes!

1. For "continuous color scales": (2. For discrete color scales)

2. For discrete color scales:

(Have fun ;))

Answer from Drakax on Stack Overflow
🌐
Plotly
community.plotly.com › 📊 plotly python
Plotly colours list - 📊 Plotly Python - Plotly Community Forum
July 13, 2018 - Hi! I’m working with Python 3 in Jupyter Notebook from the Anaconda distribution. I have a pie chart and I wold like to set the colours of my plot putting them into a list: colors = [‘#FEBFB3’, ‘#E1396C’, ‘#96D38C’, ‘#D…
🌐
Plotly
plotly.com › python › css-colors
Supported css colors in Python
These rules apply to color strings only. Numeric arrays used with a colorscale are unaffected. ... plotly.colors.hex_to_rgb converts a hexadecimal color string to a tuple of red, green, and blue values.
🌐
Plotly
plotly.com › python › builtin-colorscales
Built-in continuous color scales in Python
You can use any of the following names as string values to set continuous_color_scale or colorscale arguments. These strings are case-insensitive and you can append _r to them to reverse the order of the scale. ... import plotly.express as px from textwrap import wrap named_colorscales = px.colors.named_colorscales() print("\n".join(wrap("".join('{:<12}'.format(c) for c in named_colorscales), 96)))
🌐
Plotly
plotly.com › python › discrete-color
Discrete colors in Python
You can choose any of the following built-in qualitative color sequences from the px.colors.qualitative module, however, or define your own. ... ['#636EFA', '#EF553B', '#00CC96', '#AB63FA', '#FFA15A', '#19D3F3', '#FF6692', '#B6E880', '#FF97FF', '#FECB52'] Here is an example that creates a scatter plot using Plotly Express, with points colored using the built-in qualitative G10 color sequence.
🌐
GeeksforGeeks
geeksforgeeks.org › python › define-colors-in-a-figure-using-plotly-graph-objects-and-plotly-express
Define Colors in a Figure Using Plotly Graph Objects and Plotly Express - GeeksforGeeks
July 23, 2025 - It includes built-in color scales and supports direct color mapping. Plotly Express makes it easy to define colors based on data values:
🌐
Plotly
plotly.com › r › builtin-colorscales
Built-in continuous color scales in R
A reference for the built-in named continuous (sequential, diverging and cyclical) color scales in Plotly.
Find elsewhere
🌐
RPubs
rpubs.com › juanhklopper › color_in_Plotly_for_R
RPubs - Adding color to Plotly plots
December 8, 2018 - Adding color to Plotly plots · by Dr Juan H Klopper · Last updated almost 8 years ago · Hide Comments (–) Share Hide Toolbars ·
🌐
Observable
observablehq.com › @spattana › plotly-color-usage
Plotly Color Usage | Sumant Pattanaik
Data Visualization Using D3 and Ploty.jsMar 29, 2021 · Tinker · ojs · ojs · ojs · ojs · ojs · ojs · ojs · ojs · ojs · ojs · ojs · ojs · ojs · ojs · ojs · ojs · ojs · Comments (0) Add comment · 1 · Observable · Sign in · Sumant Pattanaik ·
🌐
Plotly
plotly.com › python › templates
Theming and templates in Python
Here is an example of loading the Template graph object for the "plotly" template, and then displaying the value of the template's layout property. ... Layout({ 'annotationdefaults': {'arrowcolor': '#2a3f5f', 'arrowhead': 0, 'arrowwidth': 1}, 'autotypenumbers': 'strict', 'coloraxis': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'colorscale': {'diverging': [[0, '#8e0152'], [0.1, '#c51b7d'], [0.2, '#de77ae'], [0.3, '#f1b6da'], [0.4, '#fde0ef'], [0.5, '#f7f7f7'], [0.6, '#e6f5d0'], [0.7, '#b8e186'], [0.8, '#7fbc41'], [0.9, '#4d9221'], [1, '#276419']], 'sequential': [[0.0, '#0d0887'], [0.1111111
🌐
Plotly
plotly.com › python-api-reference › generated › plotly.colors.html
plotly.colors package — 7.1.0 documentation
Takes a single color or an iterable of colors, as well as a list of scale values, and outputs a 2-pair of the list of color(s) converted all to an rgb or tuple color type, as well as the scale as the second element. If colors is a Plotly Scale name, then ‘scale’ will be forced to the scale from the respective colorscale and the colors in that colorscale will also be converted to the selected colortype.
🌐
GeeksforGeeks
geeksforgeeks.org › python › built-in-continuous-color-scales-in-python-plotly
Built-in Continuous Color Scales in Python Plotly - GeeksforGeeks
July 23, 2025 - Plotly has a wide variety of built-in continuous color scales that can be referenced in Python code when specifying the arguments, either by name or by reference.
🌐
Plotly
plotly.com › r › discrete-color
Discrete colors in R
This page is about using color to represent categorical data using discrete colors, but Plotly can also represent continuous values with color.
🌐
Plotly
community.plotly.com › 📊 plotly python
How to Choose the Right Colors for Your Data Visualization - 📊 Plotly Python - Plotly Community Forum
July 30, 2024 - Hello everyone! :hand_with_index_finger_and_thumb_crossed: In our last FigureFriday call, I shared some resources on choosing the right colors that I regularly use. @adamschroeder suggested that I create a separate post…
🌐
Streamlit
plotly-tools.streamlit.app
Colores en Plotly
You need to enable JavaScript to run this app
🌐
Plotly
plotly.com › python › colorscales
Continuous color scales and color bars in Python
Color scale defaults depend on the layout.colorscales attributes of the active template, and can be explicitly specified using the color_continuous_scale argument for many Plotly Express functions or the colorscale argument in various graph_objects such as layout.coloraxis or marker.colorscale in go.Scatter traces or colorscale in go.Heatmap traces.
🌐
Plotly
plotly.com › python › reference › layout › coloraxis
Layout.coloraxis in Python
Determines whether this color bar's thickness (i.e. the measure in the constant color direction) is set in units of plot "fraction" or in "pixels".
🌐
Plotly
community.plotly.com › 📊 plotly python
Automatically Pick Colors When Using `add_trace` - 📊 Plotly Python - Plotly Community Forum
December 7, 2021 - I’m using the plotly.graph_objects interface, and trying to add data with add_trace that automatically picks colors for a categorical variable. Here’s an example: data= pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/2014_usa_states.csv") fig = go.Figure().add_trace(go.Scatter(x=data['Postal'], y=data['Population'], mode='markers', marker_color=data['Postal'], ...
Top answer
1 of 2
66

First, if an explanation of the broader differences between go and px is required, please take a look here and here. And if absolutely no explanations are needed, you'll find a complete code snippet at the very end of the answer which will reveal many of the powers with colors in plotly.express


Part 1: The Essence:

It might not seem so at first, but there are very good reasons why color='red' does not work as you might expect using px. But first of all, if all you'd like to do is manually set a particular color for all markers you can do so using .update_traces(marker=dict(color='red')) thanks to pythons chaining method. But first, lets look at the deafult settings:

1.1 Plotly express defaults

Figure 1, px default scatterplot using px.Scatter

Code 1, px default scatterplot using px.Scatter

# imports
import plotly.express as px
import pandas as pd

# dataframe
df = px.data.gapminder()
df=df.query("year==2007")

# plotly express scatter plot
px.scatter(df, x="gdpPercap", y="lifeExp")

Here, as already mentioned in the question, the color is set as the first color in the default plotly sequence available through px.colors.qualitative.Plotly:

['#636EFA', # the plotly blue you can see above
 '#EF553B',
 '#00CC96',
 '#AB63FA',
 '#FFA15A',
 '#19D3F3',
 '#FF6692',
 '#B6E880',
 '#FF97FF',
 '#FECB52']

And that looks pretty good. But what if you want to change things and even add more information at the same time?

1.2: How to override the defaults and do exactly what you want with px colors:

As we alread touched upon with px.scatter, the color attribute does not take a color like red as an argument. Rather, you can for example use color='continent' to easily distinguish between different variables in a dataset. But there's so much more to colors in px:


The combination of the six following methods will let you do exactly what you'd like with colors using plotly express. Bear in mind that you do not even have to choose. You can use one, some, or all of the methods below at the same time. And one particular useful approach will reveal itself as a combinatino of 1 and 3. But we'll get to that in a bit. This is what you need to know:

1. Change the color sequence used by px with:

color_discrete_sequence=px.colors.qualitative.Alphabet

2. Assign different colors to different variables with the color argument

color = 'continent'

3. customize one or more variable colors with

color_discrete_map={"Asia": 'red'}

4. Easily group a larger subset of your variables using dict comprehension and color_discrete_map

subset = {"Asia", "Africa", "Oceania"}
group_color = {i: 'red' for i in subset}

5. Set opacity using rgba() color codes.

color_discrete_map={"Asia": 'rgba(255,0,0,0.4)'}

6. Override all settings with:

.update_traces(marker=dict(color='red'))

Part 2: The details and the plots

The following snippet will produce the plot below that shows life expectany for all continents for varying levels of GDP. The size of the markers representes different levels of populations to make things more interesting right from the get go.

Plot 2:

Code 2:

import plotly.express as px
import pandas as pd

# dataframe, input
df = px.data.gapminder()
df=df.query("year==2007")

px.scatter(df, x="gdpPercap", y="lifeExp",
           color = 'continent',
           size='pop',
          )

To illustrate the flexibility of the methods above, lets first just change the color sequence. Since we for starters are only showing one category and one color, you'll have to wait for the subsequent steps to see the real effects. But here's the same plot now with color_discrete_sequence=px.colors.qualitative.Alphabet as per step 1:

1. Change the color sequence used by px with

color_discrete_sequence=px.colors.qualitative.Alphabet

Now, let's apply the colors from the Alphabet color sequence to the different continents:

2. Assign different colors to different variables with the color argument

color = 'continent'

If you, like me, think that this particular color sequence is easy on the eye but perhaps a bit indistinguishable, you can assign a color of your choosing to one or more continents like this:

3. customize one or more variable colors with

color_discrete_map={"Asia": 'red'}

And this is pretty awesome: Now you can change the sequence and choose any color you'd like for particularly interesting variables. But the method above can get a bit tedious if you'd like to assign a particular color to a larger subset. So here's how you can do that too with a dict comprehension:

4. Assign colors to a group using a dict comprehension and color_discrete_map

# imports
import plotly.express as px
import pandas as pd

# dataframe
df = px.data.gapminder()
df=df.query("year==2007")

subset = {"Asia", "Europe", "Oceania"}
group_color = {i: 'red' for i in subset}

# plotly express scatter plot
px.scatter(df, x="gdpPercap", y="lifeExp",
           size='pop',
           color='continent',
           color_discrete_sequence=px.colors.qualitative.Alphabet,
           color_discrete_map=group_color
          )

5. Set opacity using rgba() color codes.

Now let's take one step back. If you think red suits Asia just fine, but is perhaps a bit too strong, you can adjust the opacity using a rgba color like 'rgba(255,0,0,0.4)' to get this:

Complete code for the last plot:

import plotly.express as px
import pandas as pd

# dataframe, input
df = px.data.gapminder()
df=df.query("year==2007")

px.scatter(df, x="gdpPercap", y="lifeExp",
           color_discrete_sequence=px.colors.qualitative.Alphabet,
           color = 'continent',
           size='pop',
           color_discrete_map={"Asia": 'rgba(255,0,0,0.4)'}
          )

And if you think we're getting a bit too complicated by now, you can override all settings like this again:

6. Override all settings with:

.update_traces(marker=dict(color='red'))

And this brings us right back to where we started. I hope you'll find this useful!

Complete code snippet with all options available:

# imports
import plotly.express as px
import pandas as pd

# dataframe
df = px.data.gapminder()
df=df.query("year==2007")

subset = {"Asia", "Europe", "Oceania"}
group_color = {i: 'red' for i in subset}

# plotly express scatter plot
px.scatter(df, x="gdpPercap", y="lifeExp",
           size='pop',
           color='continent',
           color_discrete_sequence=px.colors.qualitative.Alphabet,
           #color_discrete_map=group_color
           color_discrete_map={"Asia": 'rgba(255,0,0,0.4)'}
          )#.update_traces(marker=dict(color='red'))
2 of 2
0

It can be a pain to pin down the attribute name that controls color depending on go v.s. px + the class of chart in question + whether or not it accepts sets of colors as a string

import plotly.graph_objects as go

>>> dir(go.pie)
[..., Marker, ...]

>>> dir(go.pie.Marker)
[..., colors, ...]

Once you figure out the attribute

fig.update_traces(
     marker = dict(colors=px.colors.qualitative.Safe)
)