回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我尝试使用<code>Plotly</code>和<code>Python3</code>来可视化包含一些异常值的数据。离群值导致色标图例看起来很糟糕:只有很少的高数据点,但图例看起来很糟糕:2k和10k之间的空间太大。在</p>
<p>所以问题是,如何更改右边的“颜色图例”的外观(见下图),这样它将显示0到2k之间的差异?很遗憾,无法从<a href="https://plot.ly/python/logarithmic-color-scale/" rel="nofollow noreferrer">this</a>doc文件中获取答案</p>
<p>示例代码(jupyter笔记本):</p>
<pre><code>import numpy as np
from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
from plotly.graph_objs import *
init_notebook_mode()
x = np.random.randn(100,1) + 3
y = np.random.randn(100,1) + 10
x = np.reshape(x, 100)
y = np.reshape(y, 100)
color = np.random.randint(0,1000, [100])
color[[1,3,5]] = color[[1,3,5]] + 10000 # create outliers in color var
trace = Scatter(
x = x,
y = y,
mode = 'markers',
marker=dict(
color = color,
showscale=True,
colorscale = [[0, 'rgb(166,206,227, 0.5)'],
[0.05, 'rgb(31,120,180,0.5)'],
[0.1, 'rgb(178,223,138,0.5)'],
[0.15, 'rgb(51,160,44,0.5)'],
[0.2, 'rgb(251,154,153,0.5)'],
[1, 'rgb(227,26,28,0.5)']
]
)
)
fig = Figure(data=[trace])
iplot(fig)
</code></pre>
<p><a href="https://i.stack.imgur.com/t4qJp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t4qJp.png" alt="Plot"/></a></p>