我已经使用Ploly在Python语言中创建了一个六进制的"热图",通过映射多个位置(使用GPS纬度/经度)以及每个位置的值.请参见下面的代码,了解示例df和hexbin图绘制.
Data Desired个
当我将鼠标放在每个六角箱上时,我可以看到该六角箱中包含的平均值.但我想要的是一种方法,可以将每个六角箱的以下信息下载到Pandas DF中:
- 每个六进制框的平均值(已经根据下面的代码计算,但目前我只能通过将鼠标移到每个六进制框上才能访问;我希望能够将其下载到DF中)
- 每个六边形的质心GPS坐标
- 六角框的每个角的GPS坐标(即,每个六角框的每一个角的纬度和经度)
My Question个
我如何才能将上述项目中描述的数据下载到Pandas DF中?
Code example个
# Import dependencies
import pandas as pd
import numpy as np
import plotly.figure_factory as ff
import plotly.express as px
# Create a list of GPS coordinates
gps_coordinates = [[32.7792, -96.7959, 10000],
[32.7842, -96.7920, 15000],
[32.8021, -96.7819, 12000],
[32.7916, -96.7833, 26000],
[32.7842, -96.7920, 51000],
[32.7842, -96.7920, 17000],
[32.7792, -96.7959, 25000],
[32.7842, -96.7920, 19000],
[32.7842, -96.7920, 31000],
[32.7842, -96.7920, 40000]]
# Create a DataFrame with the GPS coordinates
df = pd.DataFrame(gps_coordinates, columns=['LATITUDE', 'LONGITUDE', 'Value'])
# Print the DataFrame
display(df)
# Create figure using 'df_redfin_std_by_year_and_acreage_bin' data
fig = ff.create_hexbin_mapbox(
data_frame=df, lat='LATITUDE', lon='LONGITUDE',
nx_hexagon=2,
opacity=0.2,
labels={"color": "Dollar Value"},
color='Value',
agg_func=np.mean,
color_continuous_scale="Jet",
zoom=14,
min_count=1, # This gets rid of boxes for which we have no data
height=900,
width=1600,
show_original_data=True,
original_data_marker=dict(size=5, opacity=0.6, color="deeppink"),
)
# Create the map
fig.update_layout(mapbox_style="open-street-map")
fig.show()