简体   繁体   中英

How to plot a heatmap using plt.imshow() from pandas dataset X and Y co-ordinates?

I want to plot a heatmap using XY co-ordinates I have attached below. ( I have them in a CSV file originally). I am unable to combine the two data frame columns into a valid shape for Image. plt.imshow(Z) takes only one argument for image data and I am unable to combine two columns into one. So, how to plot a heatmap using plt.imshow() in python?

X,Y coordinates here

Let's try with np.histogram2d :

hist, xe, ye = np.histogram2d(df['X'], df['Y'])
plt.imshow(hist, origin='lower')

Output (you will need to relabel the ticks)

在此处输入图片说明

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