0

I have several matrix, which i would like to show them with different colours, but in one heat map figure. For example:

import numpy as np
a=np.array([[0,0,0],[0,0,0],[1,0,0]])
b=np.array([[0,0,0],[2,2,0],[0,0,0]])
c=np.array([[3,0,0],[0,3,0],[0,0,3]])

a+b+c=np.array([[3, 0, 0],
   [2, 5, 0],
   [1, 0, 3]])

. I would like to give the non-zero position different color based on 1,2,3 in one heat map figure. There is no problem for a and b, but for b and c there overlap. So how can i show them clearly? So for the final matrix a+b+c, i hope people can understand 1 happening at 3,1 position with one color, 2 happening at 2,1 and 2,2 with another color and 3 happening at position 1,1 and 2,2 and 3,3 with the third color.

Ivy Gao
  • 111
  • 1
  • 8
  • I don't really understand your question. And the code you gave doesn't work. Could you fix it, and maybe add the part that you say there is no problem with ? Otherwise, I'll just be guessing... Thanks! – bastien girschig Aug 01 '19 at 14:07
  • Is `a` an array of 3 RGB pixels? What does your data correspond to? How do you expect the result to look? – Mark Setchell Aug 01 '19 at 15:40
  • @bastiengirschig thank you very much! I changed the code a little bite and also the explanation. Hope i explain it clearly. And let me know if it's still unclear! – Ivy Gao Aug 01 '19 at 17:59
  • @MarkSetchell The heat map means at different conditions (elements values here), they happen at different parameter space (axes of heat maps). I want people can see it i.e. different conditions (values) happen at different positions (of heat map). – Ivy Gao Aug 01 '19 at 18:01

1 Answers1

1

I'm still a little bit confused about what you are trying to achieve, but I hope this is what you're looking for

I've assigned each array to a channel in the output image (red, green and blue) This gives the following color map:

  • no values: black
  • a, b, and c have values: white
  • only a: red
  • only b: green
  • a and b have values: yellow
  • etc...

here is the snippet:

import numpy as np
from matplotlib import pyplot as plt

# input data
a = np.array([[0,0,0],[0,0,0],[1,0,0]])
b = np.array([[0,0,0],[2,2,0],[0,0,0]])
c = np.array([[3,0,0],[0,3,0],[0,0,3]])

# transform the data so that all values are either 0 or one
a = a.astype(bool)
b = b.astype(bool)
c = c.astype(bool)

# create the empty output image (heatmap)
width, height = a.shape
img = np.zeros((width, height, 3))
# put the data into the image
img[:,:,0] = a
img[:,:,1] = b
img[:,:,2] = c

plt.imshow(img)
plt.show()

And here is the result: heatmap

Hope it helps

bastien girschig
  • 663
  • 6
  • 26
  • Surely this produces an image you could include? – Mark Setchell Aug 02 '19 at 13:45
  • It sure does. Thanks for the suggestion, I've updated the answer. Note: I'm reading some passive-aggressiveness in your comment, which is rather unpleasant... – bastien girschig Aug 02 '19 at 14:23
  • You've mis-read, there is none. I like answers to be their best and most useful, and am always happy to accept suggestions for improvement myself, example from yesterday here... https://stackoverflow.com/q/57315100/2836621 – Mark Setchell Aug 02 '19 at 14:37
  • Cool. I guess I'm being too sensitive... If I can make a suggestion: make sure your comments come across as advice / request rather than criticism. – bastien girschig Aug 02 '19 at 14:56