温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

python中实现热力图的原理是什么

发布时间:2021-04-23 17:25:52 来源:亿速云 阅读:286 作者:Leah 栏目:编程语言

python中实现热力图的原理是什么?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

Python主要用来做什么

Python主要应用于:1、Web开发;2、数据科学研究;3、网络爬虫;4、嵌入式应用开发;5、游戏开发;6、桌面应用开发。

1.导入相关的packages

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

2.参数

vmax:设置颜色带的最大值

vmin:设置颜色带的最小值

cmap:设置颜色带的色系

center:设置颜色带的分界线

annot:是否显示数值注释

fmt:format的缩写,设置数值的格式化形式

linewidths:控制每个小方格之间的间距

linecolor:控制分割线的颜色

cbar_kws:关于颜色带的设置

mask:传入布尔型矩阵,若为矩阵内为True,则热力图相应的位置的数据将会被屏蔽掉(常用在绘制相关系数矩阵图)

3.实例

用Python生成heatmap比较简单,导入googlmap然后把经纬度plot在地图上就可以了。最后把heatmap生成为一个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')

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI