首页IT科技python热力图颜色设置(python热力图的原理实现)

python热力图颜色设置(python热力图的原理实现)

时间2025-05-01 17:03:56分类IT科技浏览5141
导读:在我们想要对不同变量进行判断的时候,会分析其中的之间的联系。这种理念同样也被用在实例生活中,最常见到的是做一个地理的热力图。很多人对画热力图的方法不是很清楚,我们可以先装好相关的工具,了解一些使用参数,然后在实例中进行画热力图的实例体验,下面就来看看具体的方法吧。...

在我们想要对不同变量进行判断的时候           ,会分析其中的之间的联系          。这种理念同样也被用在实例生活中               ,最常见到的是做一个地理的热力图                。很多人对画热力图的方法不是很清楚     ,我们可以先装好相关的工具           ,了解一些使用参数               ,然后在实例中进行画热力图的实例体验     ,下面就来看看具体的方法吧     。

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)

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
python里的list函数(python中numpy数组与list如何相互转换?) 外贸网站如何做好谷歌SEO优化?(提高网站排名,吸引更多目标客户流量)