0

I have a csv table, lets say: this csv table

I'm trying to create a heat map, where the higher number the warmer color is, so the goal is to have a heat map where 20 is warm, and the 0 is blue for example. I tried a lot of heat maps but all of them are looking squared and I want it to look better like this.

I used matplot but the result looks like squares, image.

and I tried using this code where data is the table that I've shown above:

n = 1e5 
Z1 = ml.bivariate_normal(data, data, 2, 2, 0, 0) 
Z2 - ml.bivariate_normal(data, data, 4, 1, 1, 1) 
ZD = Z2 - 21 
X = data.ravel() 
y = data.ravel 
z = ZD.ravel gridsize=10 
plt.subplot(111)
plt.hexbin(x, y, C=z, gridsize=gridsize, cmaprcm.jet, bins=None) 
plt.axis ([x.min(), X.max(), y.min(), y.max()])
cb = plt.colorbar() cb.set_label('mean value') plt.show()

but it shows me a linear line (don't know why maybe because the number were divided by themself, therefore, creating a linear line)

linear line image

DanielShvartz
  • 25
  • 1
  • 5

1 Answers1

0

If you look at this answer you see how to properly create the heatmap. To get your desidered result, just change the inteporlation argument from nearest to, for instance, bicubic:

import matplotlib.pyplot as plt
import numpy as np

a = np.random.random((16, 16))
plt.imshow(a, cmap="hot", interpolation="bicubic")
plt.show()

enter image description here

The other avaible interpolation options are the following: 'antialiased', 'bilinear', 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos', 'blackman'

To convert your csv file to a numpy array you can use the following code:

from numpy import genfromtxt
my_data = genfromtxt("test.csv", delimiter=",")

but, of course, you can use other data structures, like pandas dataframes (in this case use pandas.read_csv("test.csv")).

blunova
  • 2,122
  • 3
  • 9
  • 21
  • I will try it tomorrow, anyway, another problem that occurred is when I show the heatmap, it shows the map flipped vertically, I don't have a picture of it, but it shows a mirrored output, any idea on how to flip the table maybe in excel, or flip the image? – DanielShvartz Jun 08 '22 at 18:33
  • I need more details, however, you can try with the numpy function `flip` (look at the docs). – blunova Jun 08 '22 at 21:45