0

I have 2 arrays, x and y, respectively representing each point's coordinate on a 2D plane. I also have another 3 arrays of the same length as x and y. These three arrays represent the RGB values of a color. Therefore, each point in x,y correspond to a color indicated by the RGB arrays. In Python, how can I plot a heat map with x,y as its axes and colors from the three RGB arrays? Each array is, say, 1000 in length.

As an example that takes the first 10 points, I have:

x = [10.946028, 16.229064, -36.855, -38.719057, 11.231684, 33.256904999999996, -41.21, 12.294958, 16.113228, -43.429027000000005]
y = [-21.003803, 4.5, 4.5, -22.135853, 4.084630000000001, 17.860079000000002, -18.083685, -3.98297, -19.565272, 0.877016]
R = [0,1,2,3,4,5,6,7,8,9]
G = [2,4,6,8,10,12,14,16,18,20]
B = [0,255,0,255,0,255,0,255,0,255]

I'd like to draw a heat map that, for example, the first point would have the coordinates (10.946028,-21.003803) and has a color of R=0,G=2,B=0. The second point would have the coordinates (16.229064, 4.5) and has a color of R=1,G=4,B=255.

  • You want a heatmap for R, another one for G and a third one for B. So three seperate ones ? Do i get you rigth ? Can you explicitly write down the shapes of x and y, are those one column vectors like x = y = [1,1000] and in combination like adjacent matrices, describe all points in the plane. Or are both of them a matrix like [256,256] ? – Paul Higazi Jul 03 '20 at 22:38
  • @PaulHigazi Sorry I wasn't so clear before. I have updated the question to add an example. I hope this clarifies things. please let me know if it still doesn't make sense. Thanks – thrillingelf Jul 03 '20 at 23:05
  • Actually a Heatmap is a color representation of 2D information , so you can get a heatmap of the Red-Channel of an image for example. In your case that would mean 0 is black for example and 9 is white, like a grayscale visualisation. Do you want to combine all three Channels in one Heatmap ? – Paul Higazi Jul 03 '20 at 23:13
  • @PaulHigazi Right, the color on the heat map should be a color combining the RGB. so in my example the first point which has R=0,G=2,B=0 should have a color very close to black. The second point should have a blue color. – thrillingelf Jul 03 '20 at 23:39

1 Answers1

0

Ok it seems like you want like your own colormap for your heatmap. Actually you can write your own, or just use some of matplotlibs templates. Check out this post for the use of heatmaps with matplotlib. If you want to do it on your own, the easiest way is to recombine the 5 one-dimension vectors to a 3D-RGB image. Afterwards you have to define a mapping function which combines the R-G and B value to a new single value for every pixel. Like:

f(R,G,B) = a*R +b*G + c*B

a,b,c can be whatever you like, actually the formular can be way more complex, but you have to determine in which correlation the values should be. From that you get a 2D-Matrix filled with values of your function f(R,G,B). Now you have to define which value of this new matrix gets what color. This can be a linear mapping by hand (like just writing a list: 0=deep-Blue , 1= ligth-Red ...). Using this look-up table you can now get your own specific heatmap. But as you may see, that path takes some time so i would recommend not doing it and just use one of the various templates of matplotlib. Example:

import matplotlib.pyplot as plt
import numpy as np

a = np.random.random((16, 16))
plt.imshow(a, cmap='hot', interpolation='nearest')
plt.show()

You can use various types of these buy changing the string after cmap="hot" to sth of that list. Hope i could help you, gl hf.

Paul Higazi
  • 197
  • 13