简体   繁体   中英

Change color scheme of heatmap in Plotly

I wanted to create a heatmap of a probability density matrix using 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; 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 .

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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