[英]How to get the radius of the biggest bubble python plotly open street map?
To do my furthur analysis i want get the radius of the biggest bubble ?it's better if I can get another column with a bubble radius .为了进行进一步的分析,我想得到最大气泡的半径?如果我能得到另一个具有气泡半径的列会更好。
Current code:当前代码:
fig = px.scatter_mapbox(df, lat="GPSLat", lon="GPSLng", zoom=15, height=500,width=1000,
size="Count",color="Device",title=' All device :2021/01/08')
fig.update_layout(mapbox_style="satellite")
fig.show()
df:东风:
Device GPSLat GPSLng Count
1001 6.8050 80.0154 9.0
1001 6.6050 80.2154 12.0
1001 6.7050 80.4154 114.0
1002 6.8050 80.0154 2.0
1001 6.5050 80.0154 2111.0
As commented, the diameter or radius will be automatically calculated and drawn.如评论所述,将自动计算和绘制直径或半径。 If you get the drawing data, you will see that the bubble size is based on your 'Count'.
如果您获得绘图数据,您将看到气泡大小基于您的“计数”。
import plotly.express as px
import pandas as pd
import numpy as np
import io
data = '''
Device GPSLat GPSLng Count
1001 6.8050 80.0154 509.0
1001 6.6050 80.2154 1200.0
1001 6.7050 80.4154 840.0
1002 6.0050 80.0154 1602.0
1001 6.5050 80.0154 2111.0
'''
df = pd.read_csv(io.StringIO(data), delim_whitespace=True)
import plotly.express as px
px.set_mapbox_access_token(open("mapbox_api_key.txt").read())
fig = px.scatter_mapbox(df,
lat="GPSLat",
lon="GPSLng",
hover_name='Device',
height=500, width=1000,
zoom=8,
size="Count",
color="Count",
title=" All device :2021/01/08",
mapbox_style='satellite')
fig.show()
fig.data
(Scattermapbox({
'hovertemplate': ('<b>%{hovertext}</b><br><br>Cou' ... 'r>GPSLng=%{lon}<extra></extra>'),
'hovertext': array([1001., 1001., 1001., 1002., 1001.]),
'lat': array([6.805, 6.605, 6.705, 6.005, 6.505]),
'legendgroup': '',
'lon': array([80.0154, 80.2154, 80.4154, 80.0154, 80.0154]),
'marker': {'color': array([ 509., 1200., 840., 1602., 2111.]),
'coloraxis': 'coloraxis',
'size': array([ 509., 1200., 840., 1602., 2111.]),
'sizemode': 'area',
'sizeref': 5.2775},
'mode': 'markers',
'name': '',
'showlegend': False,
'subplot': 'mapbox'
}),)
# marker size
fig.data[0]['marker']['size']
array([ 509., 1200., 840., 1602., 2111.])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.