千鋒教育-做有情懷、有良心、有品質(zhì)的職業(yè)教育機構(gòu)

手機站
千鋒教育

千鋒學習站 | 隨時隨地免費學

千鋒教育

掃一掃進入千鋒手機站

領(lǐng)取全套視頻
千鋒教育

關(guān)注千鋒學習站小程序
隨時隨地免費學習課程

當前位置:首頁  >  技術(shù)干貨  > python熱力圖的原理實現(xiàn)

python熱力圖的原理實現(xiàn)

來源:千鋒教育
發(fā)布人:xqq
時間: 2023-11-13 04:38:02 1699821482

python熱力圖的原理實現(xiàn)

在我們想要對不同變量進行判斷的時候,會分析其中的之間的聯(lián)系。這種理念同樣也被用在實例生活中,最常見到的是做一個地理的熱力圖。很多人對畫熱力圖的方法不是很清楚,我們可以先裝好相關(guān)的工具,了解一些使用參數(shù),然后在實例中進行畫熱力圖的實例體驗,下面就來看看具體的方法吧。

1.導入相關(guān)的packages

importseabornassns

%matplotlibinline

sns.set(font_scale=1.5)

2.參數(shù)

vmax:設(shè)置顏色帶的值

vmin:設(shè)置顏色帶的最小值

cmap:設(shè)置顏色帶的色系

center:設(shè)置顏色帶的分界線

annot:是否顯示數(shù)值注釋

fmt:format的縮寫,設(shè)置數(shù)值的格式化形式

linewidths:控制每個小方格之間的間距

linecolor:控制分割線的顏色

cbar_kws:關(guān)于顏色帶的設(shè)置

mask:傳入布爾型矩陣,若為矩陣內(nèi)為True,則熱力圖相應的位置的數(shù)據(jù)將會被屏蔽掉(常用在繪制相關(guān)系數(shù)矩陣圖)

3.實例

用Python生成heatmap比較簡單,導入googlmap然后把經(jīng)緯度plot在地圖上就可以了。最后把heatmap生成為一個html文件,可以放大和縮小。

importgmplot#plotthelocationsongooglemap

importnumpyasnp#linearalgebra

importpandasaspd#dataprocessing,CSVfileI/O(e.g.pd.read_csv())

importmatplotlib.pyplotasplt#datavisualization

importseabornassns#datavisualization

df=pd.read_csv("data.csv")

df=pd.DataFrame(df)

df_td=pd.read_csv("datacopy.csv")

df_td=pd.DataFrame(df_td)

#printdf.dtypes

print(df.shape)

print(df_td.shape)

defplot_heat_map(data,number):

latitude_array=data['INTPTLAT'].values

latitude_list=latitude_array.tolist()

print(latitude_list[0])

Longitude_array=data['INTPTLONG'].values

longitude_list=Longitude_array.tolist()

print(longitude_list[0])

#Initializethemaptothefirstlocationinthelist

gmap=gmplot.GoogleMapPlotter(latitude_list[0],longitude_list[0],10)

#gmap.scatter(latitude_list,longitude_list,edge_width=10)

gmap.heatmap(latitude_list,longitude_list)

#WritethemapinanHTMLfile

#gmap.draw('Paths_map.html')

gmap.draw('{}_Paths_map.html'.format(number))

plot_heat_map(df,'4')

以上就是python熱力圖的原理實現(xiàn),大家可以先跟著代碼試驗一下,看看是否能運行出相關(guān)的熱力圖,然后就其中的一些知識點進行學習。更多Python學習教程請關(guān)注IT培訓機構(gòu):千鋒教育。

tags: python培訓
聲明:本站稿件版權(quán)均屬千鋒教育所有,未經(jīng)許可不得擅自轉(zhuǎn)載。
10年以上業(yè)內(nèi)強師集結(jié),手把手帶你蛻變精英
請您保持通訊暢通,專屬學習老師24小時內(nèi)將與您1V1溝通
免費領(lǐng)取
今日已有369人領(lǐng)取成功
劉同學 138****2860 剛剛成功領(lǐng)取
王同學 131****2015 剛剛成功領(lǐng)取
張同學 133****4652 剛剛成功領(lǐng)取
李同學 135****8607 剛剛成功領(lǐng)取
楊同學 132****5667 剛剛成功領(lǐng)取
岳同學 134****6652 剛剛成功領(lǐng)取
梁同學 157****2950 剛剛成功領(lǐng)取
劉同學 189****1015 剛剛成功領(lǐng)取
張同學 155****4678 剛剛成功領(lǐng)取
鄒同學 139****2907 剛剛成功領(lǐng)取
董同學 138****2867 剛剛成功領(lǐng)取
周同學 136****3602 剛剛成功領(lǐng)取
相關(guān)推薦HOT