2012-01-06 17 views
5

का उपयोग करके हीटमैप मैं दो आयामों पर स्कैटर डेटा के लिए एक हीटमैप बनाने के लिए एक स्क्रिप्ट लिख रहा हूं। निम्नलिखित मैं क्या कर कोशिश कर रहा हूँ की एक खिलौना उदाहरण है:स्कैटर डेटासेट पाइथन matplotlib

import numpy as np 
from matplotlib.pyplot import* 
x = [1,2,3,4,5] 
y = [1,2,3,4,5] 
heatmap, xedges, yedges = np.histogram2d(x, y, bins=50) 
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]] 
imshow(heatmap, extent = extent) 

मैं एक 'सबसे गरम' क्षेत्रों के साथ y = एक्स की अपेक्षा करनी चाहिए लेकिन इसके बावजूद वे यानी y = -x + 5 साथ दिखाई हीटमैप रिवर्स दिशा में एक सूची पढ़ता है। मुझे यकीन नहीं है कि यह क्यों हो रहा है। कोई सुझाव?

धन्यवाद

उत्तर

3

imshow पैरामीटर origin=lower की कोशिश करो। डिफ़ॉल्ट रूप से यह ऊपरी बाएं कोने में सरणी के (0,0) तत्व को सेट करता है।

उदाहरण के लिए:

import numpy as np 
import matplotlib.pyplot as plt 
x = [1,2,3,4,5,5] 
y = [1,2,3,4,5,5] 
heatmap, xedges, yedges = np.histogram2d(x, y, bins=10) 
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]] 
fig = plt.figure() 
ax1 = fig.add_subplot(211) 
ax1.imshow(heatmap, extent = extent) 
ax1.set_title("imshow Default"); 
ax2 = fig.add_subplot(212) 
ax2.imshow(heatmap, extent = extent,origin='lower') 
ax2.set_title("imshow origin='lower'"); 

fig.savefig('heatmap.png') 

का उत्पादन:

enter image description here

+0

महान काम करता है, धन्यवाद! – msohail

0

बहुत हीटमैप क्या आप बिखराव में देखते हैं, वास्तव में के साथ संगत की नज़र रखने का उपयोग करें:

ax2.imshow(heatmap.T, extent = extent,origin='lower')