@使用Python繪制熱力圖——Pycharm
Python繪制熱力圖,看完就會(huì)用
python繪制熱力圖簡(jiǎn)單教程,復(fù)制代碼就能用,需要表格可以留言~~~
首先需要準(zhǔn)備一個(gè)熱力圖所需的相關(guān)矩陣
格式如下:(需要這個(gè)表的可以留言~在后續(xù)操作時(shí)僅需改變表格數(shù)據(jù)就行)
熱力圖所需的相關(guān)矩陣
然后就可以畫出這樣的圖
獲取文中Excel文件,復(fù)制代碼就能用
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
#讀取文件所在位置
data = pd.read_excel("E:/onedrive/桌面/hot_map.xlsx")
#figsize設(shè)置圖片比例大?。ㄒ话闶?0,6 或 8,5)
f, ax = plt.subplots(figsize=(10,6))
ax = sns.heatmap(data.iloc[0:len(data.columns)-1,1:len(data.columns)],cmap = 'RdBu',ax=ax,annot=True)
ax.set_yticklabels(data.iloc[0:len(data.columns)-1,0], rotation=45)
ax.set_xticklabels(data.iloc[0:len(data.columns)-1,0], rotation=45)
plt.show()
代碼實(shí)現(xiàn)(需手動(dòng)操作)
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
#讀取文件所在位置
data = pd.read_excel("E:/onedrive/桌面/hot_map.xlsx")
print(data)
#figsize設(shè)置圖片比例大?。ㄒ话闶?0,6 或 8,5)
f, ax = plt.subplots(figsize=(10,6))
#數(shù)字含義:12是指標(biāo)數(shù)量;13為指標(biāo)數(shù)量+1
#annot:圖中顯示數(shù)值,如果不想要可以改為False或刪除
ax = sns.heatmap(data.iloc[0:12,1:13],cmap = 'RdBu',ax=ax,annot=True)
#定位中12為指標(biāo)數(shù)量,如果指標(biāo)名稱較短,則可以不加 rotation=45
ax.set_yticklabels(data.iloc[0:12,0], rotation=45)
ax.set_xticklabels(data.iloc[0:12,0], rotation=45)
plt.show()
其中關(guān)于"cmap顏色"通常指的是在數(shù)據(jù)可視化中使用的顏色映射(Colormap)的問題。顏色映射是將數(shù)據(jù)值映射到具體顏色的方式,常用于繪制熱力圖、散點(diǎn)圖等數(shù)據(jù)圖表中。
常見的顏色映射包括:
1、熱力圖顏色映射:常見的顏色映射包括"jet"、“viridis”、“cividis"等,用于表示數(shù)據(jù)的漸變。
2、彩虹色映射:包括"rainbow"等,但這些映射在數(shù)據(jù)可視化中不推薦使用,因?yàn)樗鼈兛赡芤鹫`導(dǎo)。
3、漸變色映射:例如"coolwarm”、"plasma"等,用于突出數(shù)據(jù)的變化。
4、自定義顏色映射:您也可以根據(jù)需要?jiǎng)?chuàng)建自定義的顏色映射。
【自己覺得比較好看的顏色,碼?。 ?mark hidden color="red">文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-770349.html
單一色調(diào):viridis,plasma
漸變色調(diào):Greys,Purples,Blues,Greens,YIGnBu
發(fā)散色調(diào):PiYG,PRGn,BrBG,coolwarm,RdBu
循環(huán)色調(diào):twilight,hsv
一些雜色:Pastel1,Pastel2,tab10,Set1
附:Excel案例表格
鏈接:https://pan.baidu.com/s/1_SifTI_aFYrUse0Wkj3ojw
提取碼:jere文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-770349.html
到了這里,關(guān)于Python 繪制熱力圖——看完就會(huì)用的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!