色标反方向

时间:2018-08-01 20:24:32

标签: python plotly

如何在绘图中反转色标的方向?我正在尝试使用color scale Viridis for a marker plot

import plotly.graph_objs as go
import plotly.plotly as py

import numpy as np

trace1 = go.Scatter(
    y = np.random.randn(500),
    mode='markers',
    marker=dict(
        size=16,
        color = np.random.randn(500), #set color equal to a variable
        colorscale='Viridis',
        showscale=True
    )
)
data = [trace1]

py.iplot(data, filename='scatter-plot-with-colorscale')

但是我希望它对于更高的值来说更暗,对于更低的值来说更亮。有没有办法定义我自己的自定义色标或更改我的颜色参数数组?

1 个答案:

答案 0 :(得分:5)

只需将reversescale = True添加到绘图定义中,色标就会反转。

import plotly
plotly.offline.init_notebook_mode()
trace = plotly.graph_objs.Heatmap(z=[[1, 20, 30],
                                     [20, 1, 60],
                                     [30, 60, 1]],
                                  reversescale=True)

plotly.offline.iplot([trace])

enter image description here