欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python熱力圖實(shí)現(xiàn)簡單方法

 更新時(shí)間:2021年01月29日 15:03:08   作者:小妮淺淺  
在本篇內(nèi)容里小編給大家分享的是一篇關(guān)于python熱力圖實(shí)現(xiàn)簡單方法,對此有興趣的朋友們可以學(xué)習(xí)下。

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

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的縮寫,設(shè)置數(shù)值的格式化形式

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

linecolor:控制分割線的顏色

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

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

3.實(shí)例

用Python生成heatmap比較簡單,導(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()

以上就是python熱力圖實(shí)現(xiàn)簡單方法的詳細(xì)內(nèi)容,更多關(guān)于python熱力圖的原理實(shí)現(xiàn)的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Python利用psutil獲取CPU與內(nèi)存等硬件信息

    Python利用psutil獲取CPU與內(nèi)存等硬件信息

    psutil是Python的一個(gè)第三方庫,提供了各種強(qiáng)大的硬件信息查閱功能,這篇文章主要為大家介紹了如何利用psutil獲取CPU與內(nèi)存等硬件信息,需要的可以參考一下
    2023-07-07
  • python中[[]] * (n)和[[] for _ in range(n)]的區(qū)別詳解

    python中[[]] * (n)和[[] for _ in 

    本文主要介紹了python中[[]] * (n)和[[] for _ in range(n)]的區(qū)別詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-02-02
  • python opencv進(jìn)行圖像拼接

    python opencv進(jìn)行圖像拼接

    這篇文章主要為大家詳細(xì)介紹了python opencv進(jìn)行圖像拼接,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • django 簡單實(shí)現(xiàn)登錄驗(yàn)證給你

    django 簡單實(shí)現(xiàn)登錄驗(yàn)證給你

    這篇文章主要介紹了django 簡單實(shí)現(xiàn)登錄驗(yàn)證給你,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • python登陸asp網(wǎng)站頁面的實(shí)現(xiàn)代碼

    python登陸asp網(wǎng)站頁面的實(shí)現(xiàn)代碼

    這篇文章主要介紹了python登陸asp網(wǎng)站頁面的實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2015-01-01
  • flask框架實(shí)現(xiàn)連接sqlite3數(shù)據(jù)庫的方法分析

    flask框架實(shí)現(xiàn)連接sqlite3數(shù)據(jù)庫的方法分析

    這篇文章主要介紹了flask框架實(shí)現(xiàn)連接sqlite3數(shù)據(jù)庫的方法,結(jié)合實(shí)例形式分析了flask框架連接sqlite3數(shù)據(jù)庫的具體操作步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2018-07-07
  • python提取log文件內(nèi)容并畫出圖表

    python提取log文件內(nèi)容并畫出圖表

    這篇文章主要介紹了python提取log文件內(nèi)容并畫出圖表,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-07-07
  • pytorch實(shí)現(xiàn)手寫數(shù)字圖片識別

    pytorch實(shí)現(xiàn)手寫數(shù)字圖片識別

    這篇文章主要為大家詳細(xì)介紹了pytorch實(shí)現(xiàn)手寫數(shù)字圖片識別,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-05-05
  • Python中Flask-RESTful編寫API接口(小白入門)

    Python中Flask-RESTful編寫API接口(小白入門)

    這篇文章主要介紹了Python中Flask-RESTful編寫API接口(小白入門),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • Python 中由 yield 實(shí)現(xiàn)異步操作

    Python 中由 yield 實(shí)現(xiàn)異步操作

    這篇文章主要介紹了Python 中由 yield 實(shí)現(xiàn)異步操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-05-05

最新評論