如何获得最大的气泡蟒蛇的半径以散乱地打开街道地图? [英] 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.
当前代码:
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.])
这篇关于如何获得最大的气泡蟒蛇的半径以散乱地打开街道地图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文