1

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:

basic-heatmap

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.

Ahsan Tarique
  • 581
  • 1
  • 11
  • 22
  • 1
    You can try use [this](https://plot.ly/python/colorscales/#custom-heatmap-colorscale) example ad create own colorscale, or specify `colorscale` parameter inside your go.Heatmap() to any of those [examples](https://community.plot.ly/t/what-colorscales-are-available-in-plotly-and-which-are-the-default/2079) and choose one that you would like the most. – Dmitriy Kisil Oct 20 '18 at 10:15

1 Answers1

5

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]
Ahsan Tarique
  • 581
  • 1
  • 11
  • 22
Lko
  • 252
  • 4
  • 12