Canonical answer as of Plotly.py 4.0 The built-in continuous colorscales are now documented here, including nice swatches: https://plot.ly/python/builtin-colorscales/ The defaults depend on which template you use, and the default template uses Plasma. See https://plot.ly/python/templates/ for more … Answer from nicolaskruchten on community.plotly.com
🌐
Plotly
plotly.com › python › builtin-colorscales
Built-in continuous color scales in Python
Many Plotly Express functions accept a color_continuous_scale argument and many trace types have a colorscale attribute in their schema. Plotly comes with a large number of built-in continuous color scales, which can be referred to in Python code when setting the above arguments, either by name in a case-insensitive string e.g.
🌐
Plotly
plotly.com › python › colorscales
Continuous color scales and color bars in Python
This document explains the following four continuous-color-related concepts: color scales represent a mapping between the range 0 to 1 and some color domain within which colors are to be interpolated (unlike discrete color sequences which are ...
🌐
Plotly
plotly.com › r › colorscales
Colorscales | R | Plotly
library(plotly) fig <- plot_ly( type = 'scatter', mode='markers', y=rep(5, 40), marker=list( size=seq(0, 39), color=seq(0, 39), colorbar=list( title='Colorbar' ), colorscale='Viridis', reversescale =T ) ) fig <- fig %>% layout( xaxis = list( showgrid = F, zeroline = F ), yaxis = list( showgrid = F, zeroline = F ) )
🌐
Plotly
plotly.com › javascript › colorscales
Colorscales in JavaScript
Over 51 examples of Colorscales including changing color, size, log axes, and more in JavaScript.
🌐
Plotly
plotly.com › python-api-reference › generated › plotly.colors.html
plotly.colors package — 7.1.0 documentation
Interpolates between colors in a colorscale to find the specific colors corresponding to the specified sample values. The colorscale can be specified as a list of [scale, color] pairs, as a list of colors, or as a named plotly colorscale.
🌐
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
community.plotly.com › 📊 plotly python
What colorscales are available in plotly, and which are the default? - 📊 Plotly Python - Plotly Community Forum
September 10, 2016 - Very confused. “Viridis” is available, but not mentioned in the documentation. There is a link Redirecting… that shows a lot of color scales, but since it’s missing Viridis, I don’t know what else it’s missing. And also I couldn’t figure out what plotly uses as a default color ...
🌐
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
🌐
Plotly
plotly.com › python-api-reference › generated › plotly.express.colors.html
plotly.express.colors package — 7.1.0 documentation
Interpolates between colors in a colorscale to find the specific colors corresponding to the specified sample values. The colorscale can be specified as a list of [scale, color] pairs, as a list of colors, or as a named plotly colorscale.
🌐
Plotly
plotly.com › javascript › reference › layout › coloraxis
Layout.coloraxis in JavaScript
Sets the colorscale. The colorscale must be an array containing arrays mapping a normalized value to an rgb, rgba, hex, hsl, hsla, hwb, or named color string. At minimum, a mapping for the lowest (0) and highest (1) values are required.
Top answer
1 of 6
20

There is a built in method from plotly.express.colors to sample_colorscale which would provide the color samples:

from plotly.express.colors import sample_colorscale

import plotly.graph_objects as go
import numpy as np

x = np.linspace(0, 1, 25)
c = sample_colorscale('jet', list(x))

fig = go.FigureWidget()
fig.add_trace(
    go.Bar(x=x, y=y, marker_color=c)
)
fig.show()

See the output figure -> sampled_colors

2 of 6
16

Plotly does not appear to have such a method, so I wrote one:

import plotly.colors

def get_continuous_color(colorscale, intermed):
    """
    Plotly continuous colorscales assign colors to the range [0, 1]. This function computes the intermediate
    color for any value in that range.

    Plotly doesn't make the colorscales directly accessible in a common format.
    Some are ready to use:
    
        colorscale = plotly.colors.PLOTLY_SCALES["Greens"]

    Others are just swatches that need to be constructed into a colorscale:

        viridis_colors, scale = plotly.colors.convert_colors_to_same_type(plotly.colors.sequential.Viridis)
        colorscale = plotly.colors.make_colorscale(viridis_colors, scale=scale)

    :param colorscale: A plotly continuous colorscale defined with RGB string colors.
    :param intermed: value in the range [0, 1]
    :return: color in rgb string format
    :rtype: str
    """
    if len(colorscale) < 1:
        raise ValueError("colorscale must have at least one color")

    if intermed <= 0 or len(colorscale) == 1:
        return colorscale[0][1]
    if intermed >= 1:
        return colorscale[-1][1]

    for cutoff, color in colorscale:
        if intermed > cutoff:
            low_cutoff, low_color = cutoff, color
        else:
            high_cutoff, high_color = cutoff, color
            break

    # noinspection PyUnboundLocalVariable
    return plotly.colors.find_intermediate_color(
        lowcolor=low_color, highcolor=high_color,
        intermed=((intermed - low_cutoff) / (high_cutoff - low_cutoff)),
        colortype="rgb")

The challenge is that the built-in Plotly colorscales are not consistently exposed. Some are defined as a colorscale already, others as just a list of color swatches that must be converted to a color scale first.

The Viridis colorscale is defined with hex values, which the Plotly color manipulation methods don't like, so it's easiest to construct it from swatches like this:

viridis_colors, _ = plotly.colors.convert_colors_to_same_type(plotly.colors.sequential.Viridis)
colorscale = plotly.colors.make_colorscale(viridis_colors)

get_continuous_color(colorscale, intermed=0.25)
# rgb(58.75, 80.75, 138.25)
🌐
Plotly
plotly.com › python › reference › layout › coloraxis
Layout.coloraxis in Python
Sets the colorscale. The colorscale must be an array containing arrays mapping a normalized value to an rgb, rgba, hex, hsl, hsla, hwb, or named color string. At minimum, a mapping for the lowest (0) and highest (1) values are required.
🌐
Notebook Community
notebook.community › empet › Plotly-plots › Plotly-asymmetric-colorscales
Plotly asymmetric diverging colorscales adapted to data
We illustrate below how we can define a custom diverging matplotlib colormap, respectively a Plotly colorscale, starting with a list of three colors (left, mid and right color).
🌐
Plotly
community.plotly.com › 📊 plotly python
How can I make custom color scales? - 📊 Plotly Python - Plotly Community Forum
November 8, 2023 - Is it possible to make custom color scales instead of using the built-in ones? I would like to make a custom color scale to use in my plots (scatter plots generally I think) in which I can set the colors. For example bl…
🌐
Plotly
plotly.com › fsharp › logarithmic-color-scale
Continuous Color Scales and Color Bars | Fsharp | Plotly
open FSharp.Data type jsondata = JsonProvider<"https://raw.githubusercontent.com/plotly/datasets/master/custom_heatmap_colorscale.json"> let data = jsondata.Load("https://raw.githubusercontent.com/plotly/datasets/master/custom_heatmap_colorscale.json") In [10]: let z = data.Z //let customColorscale = StyleParam.Colorscale.Custom [(0.0,"#A6CEE3");(1.0,"#E31A1C")] let customColorscale = StyleParam.Colorscale.Custom [(0.0,"rgb(165,0,38)");(0.11,"rgb(215,48,39)");(0.22,"rgb(244,109,67)"); (0.33,"rgb(253,174,97)");(0.44,"rgb(254,224,144)");(0.55,"rgb(224,243,248)"); (0.66,"rgb(171,217,233)");(0.77,
Top answer
1 of 2
35

Generally, changing the color scheme for a plotly express figure is very straight-forward. What's causing the problems here is the fact that species is a categorical variable. Continuous or numerical values are actually easier, but we'll get to that in a bit.

For categorical values, using color_discrete_map is a perfectly valid, albeit cumbersome approach. I prefer using the keyword argument continuous_colorscale in combination with px.colors.qualitative.Antique, where Antique can be changed to any of the discrete color schemes available in plotly express. Just run dir(px.colors.qualitative) to see what are available to you in the plotly version you are running:

['Alphabet',
 'Antique',
 'Bold',
 'D3',
 'Dark2',
 'Dark24',
 'G10',......]

Code 1:

import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length",
                 color="species", color_discrete_sequence=px.colors.qualitative.Antique)

fig.show()

Plot 1:

So what about continuous variables?

Consider the following snippet:

import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length",
                 color="sepal_length", color_continuous_scale=px.colors.sequential.Viridis)

fig.show()

Running this will produce this plot:

You can change the colors to any other theme available under dir(px.colors.sequential), for example color_continuous_scale=px.colors.sequential.Inferno, and get this plot:

What's possibly causing confusion here, is that setting color='species, and keeping color_continuous_scale=px.colors.sequential.Inferno will give you this plot:

The figure now jumps straight back to using the default plotly colors, without giving you any warning about color_continuous_scale=px.colors.sequential.Inferno not having an effect. This is because species is a categorical variable with these different values : ['setosa', 'versicolor', 'virginica'], so color_continuous_scale is simply ignored. For color_continuous_scale to take effect you'll have to use a numerical value, like sepal_length = [5.1, 4.9, 4.7, 4.6, 5. , 5.4, ...]

And this brings us right back to my initial answer for categorical values:

Use the keyword argument continuous_colorscale in combination with px.colors.qualitative

2 of 2
20

You can use a method called color_discrete_map, which is a dict of k,v pairs where the k is the value for the color and v is the colorscheme. For example:

fig = px.scatter(df, x='sepal_length', y='sepal_width',
              color='species', color_discrete_map={'setosa': 'lightcyan', 
                                                   'versicolor': 'royalblue', 'virginica': 'darkblue'})

🌐
Plotly
plotly.com › python › discrete-color
Discrete colors in Python
No interpolation occurs when using color sequences, unlike with continuous color scales, and each color is used as-is. Color sequence defaults depend on the layout.colorway attribute of the active template, and can be explicitly specified using the color_discrete_sequence argument for many Plotly Express functions.