How to change a color bar in Plotly in Python
Last Updated :
28 Nov, 2021
In this article, we will learn how to change a color bar in Plotly Python.
Different types Color-Scale names for Plotly
aggrnyl |
burg |
inferno |
plasma |
rdpu |
ylgnbu |
matter |
geyser |
agsunset |
burgyl |
jet |
plotly3 |
redor |
ylorbr |
solar |
piyg |
blackbody |
cividis |
magenta |
pubu |
reds |
ylorrd |
speed |
picnic |
blues |
darkmint |
magma |
pubugn |
sunset |
algae |
tempo |
portland |
bluered |
electric |
mint |
purd |
sunsetdark |
amp |
thermal |
puor |
blugrn |
emrld |
orrd |
purp |
teal |
deep |
turbid |
rdgy |
bluyl |
gnbu |
oranges |
purples |
tealgrn |
dense |
armyrose |
rdylbu |
brwnyl |
greens |
oryel |
purpor |
turbo |
gray |
brbg |
rdylgn |
bugn |
greys |
peach |
rainbow |
viridis |
haline |
earth |
spectral |
bupu |
hot |
pinkyl |
rdbu |
ylgn |
ice |
fall |
tealrose |
temps |
tropic |
balance |
curl |
delta |
oxy |
edge |
hsv |
icefire |
phase |
twilight |
mrybm |
mygbm |
|
|
|
Syntax:
We can change the color by using the color scale.
fig = go.Figure(data=go.Scatter(
y=np.random.randn(500),
mode='markers',
marker=dict(
size=8,
# set color equal to a variable
color=np.random.randn(500),
# one of plotly colorscales
colorscale='hot',
# enable color scale
showscale=True
)
))
Example 1:
Python3
import plotly.graph_objects as go
import numpy as np
fig = go.Figure(data = go.Scatter(
y = np.random.randn( 500 ),
mode = 'markers' ,
marker = dict (
size = 8 ,
color = np.random.randn( 500 ),
colorscale = 'hot' ,
showscale = True
)
))
fig.show()
|
Output:
Example 2:
Set color to hot_r
Python3
import plotly.graph_objects as go
import numpy as np
fig = go.Figure(data = go.Line(
y = np.random.randn( 500 ),
mode = 'markers' ,
marker = dict (
size = 8 ,
color = np.random.randn( 500 ),
colorscale = 'hot_r' ,
showscale = True
)
))
fig.show()
|
Output:
Example 3:
Set color to turbo_r
Python3
import plotly.graph_objects as go
import numpy as np
fig = go.Figure(data = go.Scatter(
y = np.random.randn( 500 ),
mode = 'markers' ,
marker = dict (
size = 8 ,
color = np.random.randn( 550 ),
colorscale = 'turbo_r' ,
showscale = True
)
))
fig.show()
|
Output:
Share your thoughts in the comments
Please Login to comment...