4

I want to change the colour scheme of the 3D surface plot in the plotly python. Plotly assigns the colour scheme by default as shown in figure below.

Plot 1

Here is my code

import import plotly.graph_objects as go
import pandas as pd

data = pd.read_csv('\Data.csv')
data.set_index("years", inplace = True)
figure = go.Figure(data=[go.Surface(z=data.values)])
figure.update_layout(
            scene = dict(
                xaxis = dict(
                    title = 'Months',
                    #nticks = 5,
                    autorange='reversed',
                    showgrid=True, 
                    gridwidth=1, 
                    gridcolor='Blue',
                    ticktext = data.columns,
                    tickvals= list(range(0,data.shape[1]))),
                
                    
                yaxis = dict(
                    title = 'years',
                    showgrid=True, 
                    gridwidth=1, 
                    gridcolor='Blue',
                    ticktext = data.index,
                    tickvals= list(range(0,data.shape[0]))),
              
                zaxis = dict(
                    title = 'Discharge (Cumecs)',
                    #showgrid=True, 
                    gridwidth=1,
                    gridcolor='Blue')),
           tilte = 'Plot 1'
)
vestland
  • 55,229
  • 37
  • 187
  • 305
Asif Marazi
  • 127
  • 2
  • 11
  • I find [this answer](https://stackoverflow.com/questions/53992606/plotly-different-color-surfaces) to be very helpful. – r-beginners Feb 04 '21 at 12:31

1 Answers1

5

You can easily change the colour scheme through colorscale in

go.Surface(colorscale ='<color>')

Here's an example using colorscale='Blues:

fig = go.Figure(data=[go.Surface(z=z_data.values, colorscale ='Blues')])

Plot

enter image description here

Your colorscale options are (but not necessarily limited to):

Greys,YlGnBu,Greens,YlOrRd,Bluered,RdBu,Reds,Blues,Picnic,Rainbow,Portland,Jet,Hot,Blackbody,Earth,Electric,Viridis,Cividis.

Sample code:

import plotly.graph_objects as go

import pandas as pd

# Read data from a csv
z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/api_docs/mt_bruno_elevation.csv')

fig = go.Figure(data=[go.Surface(z=z_data.values, colorscale ='Blues')])

fig.update_layout(title='Mt Bruno Elevation', autosize=False,
                  width=500, height=500,
                  margin=dict(l=65, r=50, b=65, t=90))
f = fig.full_figure_for_development(warn=False)


fig.show()
vestland
  • 55,229
  • 37
  • 187
  • 305
  • 1
    Thanks a lot...as a newbie I miss a lots of simple things... – Asif Marazi Feb 04 '21 at 16:55
  • 1
    @AsifMarazi Newbie or not, in my humble opinion you're off to a *very* good start on SO. You've asked a question that did not have a very easily googlable (not sure if that is a word though =) answer, and you've provided an *almost* reproducible code snippet. And that's more than we see from most of the newbies in here. But more importantly, you've proven that an answer to your question has a value above zero to you by providing swift feedback through commenting on, and accepting, a suggested solution. Keep up the good work, and you will learn **a lot** in here. See you around! – vestland Feb 04 '21 at 23:48
  • 1
    Sorry for the delayed response...I am currently very much enthusiastic to learn programming and your help is surely needed...Thanks for your appreciation... – Asif Marazi Feb 05 '21 at 15:58