使用python怎么實(shí)現(xiàn)一個(gè)熱力圖效果-創(chuàng)新互聯(lián)

今天就跟大家聊聊有關(guān)使用python怎么實(shí)現(xiàn)一個(gè)熱力圖效果,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

創(chuàng)新互聯(lián)是少有的網(wǎng)站制作、成都做網(wǎng)站、營(yíng)銷(xiāo)型企業(yè)網(wǎng)站、小程序開(kāi)發(fā)、手機(jī)APP,開(kāi)發(fā)、制作、設(shè)計(jì)、賣(mài)鏈接、推廣優(yōu)化一站式服務(wù)網(wǎng)絡(luò)公司,從2013年創(chuàng)立,堅(jiān)持透明化,價(jià)格低,無(wú)套路經(jīng)營(yíng)理念。讓網(wǎng)頁(yè)驚喜每一位訪客多年來(lái)深受用戶好評(píng)

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


import seaborn as sns
%matplotlib inline
sns.set(font_scale=1.5)

2.參數(shù)

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

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

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

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

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

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

linewidths:控制每個(gè)小方格之間的間距

linecolor:控制分割線的顏色

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

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

3.實(shí)例

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

import gmplot       # plot the locations on google map
import numpy as np    # linear algebra
import pandas as pd    # data processing, CSV file I/O (e.g. pd.read_csv())
import matplotlib.pyplot as plt # data visualization
import seaborn as sns    # data visualization
df = pd.read_csv("data.csv")
df = pd.DataFrame(df)
df_td = pd.read_csv("datacopy.csv")
df_td = pd.DataFrame(df_td)
# print df.dtypes
print (df.shape)
print (df_td.shape)
def plot_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])
  # Initialize the map to the first location in the list
  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)
  # Write the map in an HTML file
  # gmap.draw('Paths_map.html')
  gmap.draw('{}_Paths_map.html'.format(number))
plot_heat_map(df,'4')

內(nèi)容擴(kuò)展:

實(shí)例擴(kuò)展1

# -*- coding: utf-8 -*-
from pyheatmap.heatmap import HeatMap
import numpy as np
N = 10000
X = np.random.rand(N) * 255 # [0, 255]
Y = np.random.rand(N) * 255
data = []
for i in range(N):
 tmp = [int(X[i]), int(Y[i]), 1]
 data.append(tmp)
heat = HeatMap(data)
heat.clickmap(save_as="1.png") #點(diǎn)擊圖
heat.heatmap(save_as="2.png") #熱圖

實(shí)例擴(kuò)展2

import matplotlib.pyplot as plt
import matplotlib.cm as cm
from matplotlib.colors import LogNorm
import numpy as np
x, y = np.random.rand(10), np.random.rand(10)
z = (np.random.rand(9000000)+np.linspace(0,1, 9000000)).reshape(3000, 3000)
plt.imshow(z+10, extent=(np.amin(x), np.amax(x), np.amin(y), np.amax(y)),
  cmap=cm.hot, norm=LogNorm())
plt.colorbar()
plt.show()

看完上述內(nèi)容,你們對(duì)使用python怎么實(shí)現(xiàn)一個(gè)熱力圖效果有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

名稱欄目:使用python怎么實(shí)現(xiàn)一個(gè)熱力圖效果-創(chuàng)新互聯(lián)
當(dāng)前路徑:http://muchs.cn/article38/idjpp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、虛擬主機(jī)、企業(yè)建站、做網(wǎng)站、品牌網(wǎng)站建設(shè)軟件開(kāi)發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作