简体   繁体   English

在Plotly中更改热图的配色方案

[英]Change color scheme of heatmap in Plotly

I wanted to create a heatmap of a probability density matrix using plotly. 我想使用plotly创建一个概率密度矩阵的热图。

import numpy as np
from plotly.offline import download_plotlyjs, init_notebook_mode, plot
import plotly.graph_objs as go

probability_matrix = np.loadtxt("/path/to/file")
trace = go.Heatmap(z = probability_matrix)
data=[trace]
plot(data, filename='basic-heatmap')

This gives me an image like this: 这给了我这样的图像:

基本-热图

But after printing the image on a piece of paper, it looks very dark (color printing) and becomes completely indiscernible after black and white printing. 但是,在一张纸上打印完图像后,它看起来很暗(彩色打印),在黑白打印后变得完全无法分辨。 I was wondering if I could change the color range arbitrarily; 我想知道是否可以任意更改颜色范围; so that the whole image looks a bit softer or lighter. 这样整个图像看起来会更柔和或更亮。

For example: 1 could be white and 0 could be very light blue or a softer color; 例如:1可以是白色,0可以是非常浅的蓝色或更柔和的颜色; so that the whole image looks more lighter after printing on a paper. 因此,在纸张上打印后,整个图像看起来更亮。

Note: not sure if this should be a separate question, since I have asked another question related to plotly here . 注意:不知道这是否应该是一个单独的问题,因为我在这里询问了另一个与plotly有关的问题。

You will need to manually insert a colour scale 您将需要手动插入色标

trace = go.Heatmap(z=probability_matrix, colorscale=[[0.0, '#F5FFFA'], 
                         [0.2, '#ADD8E6'], 
                         [0.4, '#87CEEB'],
                         [0.6, '#87CEFA'], 
                         [0.8, '#40E0D0'], 
                         [1.0, '#00CED1']])
data=[trace]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM