Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

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 the modules
import plotly.graph_objects as go
import numpy as np
  
# create figure
# from the data using numpy random method
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
    )
))
  
# display figure
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), #set color equal to a variable
        colorscale='hot_r', # one of plotly colorscales
        showscale=True  # enable color scale
    )
))
  
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,
        
        # set color equal to a variable
        color=np.random.randn(550),
          
        # one of plotly colorscales
        colorscale='turbo_r',
          
        # enable color scale
        showscale=True
    )
))
# display
fig.show()


Output:


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!