在我们想要对不同变量进行判断的时候,会分析其中的之间的联系。这种理念同样也被用在实例生活中,最常见到的是做一个地理的热力图。很多人对画热力图的方法不是很清楚,我们可以先装好相关的工具,了解一些使用参数,然后在实例中进行画热力图的实例体验,下面就来看看具体的方法吧。
1.导入相关的packages
importseabornassns %matplotlibinline 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文件,可以放大和缩小。
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')
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)