I found the solution here Continuous color scales and color bars in Python Answer from Kansai on community.plotly.com
🌐
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 blue for negative numbers , red for positive numbers and…
🌐
Plotly
plotly.com › python › builtin-colorscales
Built-in continuous color scales in Python
px.scatter(color_continuous_scale="Viridis") or by reference e.g. go.Scatter(marker_colorscale=plotly.colors.sequential.Viridis). They can also be reversed by adding _r at the end e.g.
🌐
CodePen
codepen.io › plotly › pen › NqmRga
Custom Colorscale with Plotly.js
Plotly.d3.json('https://raw.githubusercontent.com/plotly/datasets/master/custom_heatmap_colorscale.json', function(figure) { var data = [{ z: figure.z, colorscale: [ ['0.0', 'rgb(165,0,38)'], ['0.111111111111', 'rgb(215,48,39)'], ['0.222222222222', ...
🌐
Plotly
plotly.com › python › colorscales
Continuous color scales and color bars in Python
Color scale defaults depend on ... 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 ...
🌐
Naomi Aro
naomiaro.hashnode.dev › how-to-create-custom-continuous-and-discrete-colorscales-with-plotlyjs
How to create custom continuous and discrete colorscales with Plotly.js
September 9, 2024 - Below I've taken a part of the ... build a custom colour scale based off of this data. The elevations legend shows a minimum and maximum elevation given in feet and the colour which should represent a data point in this range. Following the Plotly.js scatter colorscale reference ...
🌐
Plotly
plotly.com › javascript › colorscales
Colorscales in JavaScript
d3.json('https://raw.githubusercontent.com/plotly/datasets/master/custom_heatmap_colorscale.json', function(figure) { var data = [{ z: figure.z, colorscale: 'YlOrRd', type: 'heatmap' } ]; var layout = { title: { text: 'YlOrRd' } }; Plotly.newPlot('myDiv', data, layout); });
🌐
Plotly
community.plotly.com › dash python
Dash Newbie - Heatmap Custom Color Scales Per Column - Dash Python - Plotly Community Forum
April 30, 2023 - Hello, found this forum from the book “The Book Of Dash” and I’m hopeful someone can assist me on this problem. I’ve managed to stumble through a few examples and create my own annotated heatmap, reading in data from .csv files and all, but I don’t like the built-in colorscale.
🌐
Plotly
plotly.com › fsharp › colorscales
Continuous color scales and color bars in Fsharp
let z = [| [| 10.0; 10.625; 12.5; 15.625; 20.0 |] [| 5.625; 6.25; 8.125; 11.25; 15.625 |] [| 2.5; 3.125; 5.0; 8.125; 12.5 |] [| 0.625; 1.25; 3.125; 6.25; 10.625 |] [| 0.0; 0.625; 2.5; 5.625; 10.0 |] |] //let customColorscale = StyleParam.Colorscale.Custom [(0.0,"#A6CEE3");(1.0,"#E31A1C")] let customColorscale = StyleParam.Colorscale.Custom [ (0.0, "rgb(166,206,227)") (0.25, "rgb(31,120,180)") (0.45, "rgb(178,223,138)") (0.65, "rgb(51,160,44)") (0.85, "rgb(251,154,153)") (1.0, "rgb(227,26,28)") ] Chart.Contour(z,Colorscale=customColorscale) |> Chart.withSize(600.,600.) Out[8]: Like axes, you ca
Find elsewhere
🌐
Plotly
community.plotly.com › 📊 plotly python
How to customize the color_continuous_scale in plotly? - 📊 Plotly Python - Plotly Community Forum
March 8, 2022 - 我想用plotly的热力图强调某个区间数据, 比如:下图,我想让显示黄色的取值区间为146-317, 或者说当取值范围在146-317时显示黄色,我该咋做呢? I want to use plotly’s heat map to emphasize a certain range of data, for example: in the figure below, I want to display the value range of yellow as 146-317, or display yellow when the value range is 146-317, what should I do?
🌐
Plotly
community.plotly.com › 📊 plotly python
Treemap Custom scale color scale - 📊 Plotly Python - Plotly Community Forum
April 29, 2021 - Hi Everyone, I am new in Dash and Plotly environnement, great tools ! I am currently working on Treemap. So far I successfully read my excel, extract data and buil a hierarchical dataframe to be read by plotly Treemap ( go.Treemap). I am now struggling to create a custom colorscale based on a custom scale.
🌐
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
community.plotly.com › plotly.js
Custom Color Scale for Scatter Chart - plotly.js - Plotly Community Forum
November 4, 2021 - I have a scatter plot with multiple series as such: let scatterPlot = { x: scatterData.map((a) => a.x), y: scatterData.map((a) => a.y), name: data.seriesName, type: 'scattergl', mode: 'markers', marker: { color: scatterData.map((a) => a.color), size: scatterData.map((a) => a.size), }, }; As you can see, the color for each marker poi...
Top answer
1 of 1
12

The code you use to generate a color palette works just fine. You only need to provide data that match with a heatmap. The following code provides this:

library(RColorBrewer)
library(plotly)

# your palette definition
palette <- colorRampPalette(c("darkblue", "blue", "lightblue1",
                              "green","yellow", "red", "darkred"))

set.seed(9876)    # for reproducibility

## a complete random set
hmdata <- matrix(data = sample(x = 1:10^6, size = 100*100), nrow = 100, ncol = 100)
plot_ly(z = hmdata, colors = palette(50), type = "heatmap")

This gives the following heatmap:

## a random set that has been sorted
hmdata_s <- matrix(data = sort(sample(x = 1:10^6, size = 100*100)), nrow = 100, ncol = 100)
plot_ly(z = hmdata_s, colors = palette(50), type = "heatmap")

Yielding this plot:

Please let me know whether this is what you want.

UPDATE

you can set custom scale in plot_ly with zauto, zmax, and zmin. The following 2 pieces of code and graphs will illustrate this:

The scale is set from 1 to 100 and the data vary similarly:

hmdata_s3 <- matrix(data = sort(sample(x = 1:100, size = 100*100, replace = TRUE)), nrow = 100, ncol = 100)
plot_ly(z = hmdata_s3, colors = palette(50), type = "heatmap", zauto = FALSE, zmin = 1, zmax = 100)

The scale is set from 1 to 100 and the data vary between 50 and 100 only

hmdata_s4 <- matrix(data = sort(sample(x = 50:100, size = 100*100, replace = TRUE)), nrow = 100, ncol = 100)
plot_ly(z = hmdata_s4, colors = palette(50), type = "heatmap", zauto = FALSE, zmin = 1, zmax = 100)

🌐
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 › 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,
🌐
Notebook Community
notebook.community › empet › Plotly-plots › Plotly-asymmetric-colorscales
Plotly asymmetric diverging colorscales adapted to data
The resulted financial-type colorscale is represented by the following list: ... fin_cs=[[0.0, u'#df0101'], [0.1, u'#e33129'], [0.2, u'#e86353'], [0.3, u'#ec937b'], [0.4, u'#f1c5a5'], [0.5, u'#f4f6cd'], [0.6, u'#cee9a6'], [0.7, u'#a6db7c'], [0.8, u'#7fce55'], [0.9, u'#57c12c'], [1.0, u'#31b404']] Seaborn provides a function for defining custom diverging matplotlib colormaps, that can be transformed in Plotly colorscales: