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     burginferno     plasma      rdpu        ylgnbu      mattergeyser
agsunset    burgyl      jet         plotly3redorylorbr      solarpiyg
blackbodycividismagenta     pubu        reds        ylorrd      speedpicnic
blues       darkmintmagmapubugn      sunsetalgae       tempoportland
bluered     electricmintpurd        sunsetdark  amp         thermalpuor
blugrn      emrldorrdpurptealdeepturbidrdgy
bluyl       gnbuorangespurplestealgrn     dense       armyroserdylbu
brwnylgreensoryel       purporturbogray        brbgrdylgn
bugn        greyspeachrainbow     viridishaline      earthspectral
bupu        hotpinkylrdbuylgn        ice         falltealrose
tempstropicbalancecurldeltaoxyedgehsv
icefirephasetwilightmrybmmygbm   

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!