How can I reverse the direction of a colorscale in plotly? I am trying to use the color scale Viridis for a marker plot
JavaScript
x
19
19
1
import plotly.graph_objs as go
2
import plotly.plotly as py
3
4
import numpy as np
5
6
trace1 = go.Scatter(
7
y = np.random.randn(500),
8
mode='markers',
9
marker=dict(
10
size=16,
11
color = np.random.randn(500), #set color equal to a variable
12
colorscale='Viridis',
13
showscale=True
14
)
15
)
16
data = [trace1]
17
18
py.iplot(data, filename='scatter-plot-with-colorscale')
19
but I want it to be darker for higher values and lighter for lower values. Is there any way to do this without defining my own custom colorscale or changing my color parameter array?
Advertisement
Answer
Just add reversescale = True
to your plot definition and the colorscale is reversed.
JavaScript
1
9
1
import plotly
2
plotly.offline.init_notebook_mode()
3
trace = plotly.graph_objs.Heatmap(z=[[1, 20, 30],
4
[20, 1, 60],
5
[30, 60, 1]],
6
reversescale=True)
7
8
plotly.offline.iplot([trace])
9