如何对经度和纬度进行分箱并绘制分箱的密度?

编程入门 行业动态 更新时间:2024-10-28 20:20:18
本文介绍了如何对经度和纬度进行分箱并绘制分箱的密度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在测试以下代码.

import numpy as np import pandas as pd #import matplotlib.pyplot as plt #plt.style.use('seaborn-white') df = pd.read_csv('C:\\Users\\ryans\\OneDrive\\Desktop\\business.csv') X = df[['latitude','longitude','address']].copy() X['latitude'].value_counts() X['longitude'].value_counts()

结果:

-115.123695 168 -111.940325 167 -115.171130 158 -111.821087 157 -115.224485 156 -82.032188 1 -89.383229 1 -89.533178 1 -81.475399 1 -111.857103 1

下一步...

X['lat'] = pd.cut(df['latitude'], bins=10) X['lon'] = pd.cut(df['longitude'], bins=10) print(X)

结果:

latitude longitude ... lat lon 0 33.522143 -112.018481 ... (33.187, 35.014] (-115.536, -111.235] 1 43.605499 -79.652289 ... (42.252, 44.062] (-81.428, -77.17] 2 35.092564 -80.859132 ... (35.014, 36.824] (-81.428, -77.17] 3 33.455613 -112.395596 ... (33.187, 35.014] (-115.536, -111.235] 4 35.190012 -80.887223 ... (35.014, 36.824] (-81.428, -77.17] ... ... ... ... ... 192604 36.213732 -115.177059 ... (35.014, 36.824] (-115.536, -111.235] 192605 44.052658 -79.481850 ... (42.252, 44.062] (-81.428, -77.17] 192606 33.679992 -112.035569 ... (33.187, 35.014] (-115.536, -111.235] 192607 33.416137 -111.735743 ... (33.187, 35.014] (-115.536, -111.235] 192608 36.107267 -115.171920 ... (35.014, 36.824] (-115.536, -111.235]

现在,我正在尝试可视化这些坐标箱,并绘制这些箱的密度.因此,计数越高,颜色越浓.有可能吗?

Now, I am trying to visualize these bins of coordinates, and plot the densities of bins. So, the higher the counts, the more intense the color. Is that possible?

我在网上找到了两个示例,这些示例显示了如何创建经度和纬度数据的热图.那是唯一的办法吗,还是可以对这些数据点进行装箱?

I found a couple examples on line, which show how to create heat maps of longitude and latitude data. Is that the only to do it, or is it possible to bin these data points?

推荐答案

以下代码可以很好地完成工作!

The following code does a pretty nice job!

import pandas as pd import folium from folium.plugins import HeatMap df = pd.read_csv('C:\\your_path\\business.csv') df.head(3) max_amount = float(df['review_count'].max()) hmap = folium.Map(location=[42.5, -75.5], zoom_start=7, ) hm_wide = HeatMap( list(zip(df.latitude.values, df.longitude.values, df.review_count.values)), min_opacity=0.2, max_val=max_amount, radius=17, blur=15, max_zoom=1, ) hmap.add_child(hm_wide)

我需要处理其中某些颜色的不透明度和强度,但是这个概念绝对是合理的.

I need to play with the opacity and the intensity of some of those colors, but the concept definitely makes sense.

更多推荐

如何对经度和纬度进行分箱并绘制分箱的密度?

本文发布于:2023-07-28 00:08:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1225552.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:经度   纬度   密度

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!