Heatmap with text in each cell with matplotlib's pyplot -


मैं matplotlib के साथ एक हीटमैप साजिश करने के लिए उपयोग करता हूं:

 <कोड> plt डीईएफ़ हीटमैप (डेटा, शीर्षक, xlabel, ylabel के रूप में एन पी आयात matplotlib.pyplot के रूप में आयात numpy ): plt.figure () plt.title (शीर्षक) plt.xlabel (xlabel) plt.ylabel (ylabel) c = plt.pcolor (डेटा, edgecolors = 'k', linewidths = 4, CMAP = 'RdBu', vmin = 0.0, VMAX = 1.0) plt.colorbar (ग) डीईएफ़ मुख्य (): शीर्षक = "आरओसी के एयूसी" xlabel = "शिफ़्ट होने के समय" ylabel = "तराजू" डेटा = np.random.rand (8,12) हीटमैप (डेटा, शीर्षक, xlabel, ylabel) plt.show () यदि __name__ == "__main__": मुख्य ()  

क्या प्रत्येक सेल में संगत मान जोड़ने का कोई तरीका है, जैसे:

(Matlab से)

यहां छवि विवरण दर्ज करें

< P> (मेरे वर्तमान आवेदन के लिए मुझे अतिरिक्त % की आवश्यकता नहीं है, हालांकि मुझे उत्सुकता होगी भविष्य के लिए जानने के लिए)

आपको axes.text () , यहाँ एक उदाहरण है:

  plt title = के रूप में एन पी आयात matplotlib.pyplot के रूप में आयात numpy "आरओसी के एयूसी" xlabel = "शिफ़्ट होने के समय" ylabel = "तराजू" डेटा = np.random.rand (8,12) plt.figure (figsize = (12, 6)) plt.title (शीर्षक) plt.xlabel (xlabel) plt.ylabel (ylabel) c = plt.pcolor (डेटा, edgecolors = 'k', linewidths = 4, CMAP = 'RdBu', vmin = 0.0, VMAX = 1.0) डीईएफ़ show_values ​​(पीसी, fmt = "% 2f।", ** kw): itertools से izip pc.update_scalarmappable आयात () कुल्हाड़ी = Pc.get_axes () के लिए पी, रंग, izip में मान (pc.get_paths (), pc.get_facecolors (), pc.get_array ()): x, y = p.vertices [: - 2,:] मतलब (0) अगर np.all (रंग [: 3] & gt; 0.5): रंग = (0.0, 0.0, 0.0) अन्य: रंग = (1.0, 1.0, 1.0) ax.text (x, y, fmt% value, ha = "center", va = "center", रंग = रंग , ** kw) show_values ​​(c) plt.colorbar (c)  

आउटपुट:


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -