Python 在不使用Jupyter笔记本电脑的情况下以绘图方式刷新数据
我花了很多时间寻找一种可以在不重新启动页面和不使用Jupyter笔记本/小部件的情况下更新Plotly Scattergeo(世界地图)的东西 基本上,我希望有一个“按钮”Python 在不使用Jupyter笔记本电脑的情况下以绘图方式刷新数据,python,plotly,Python,Plotly,我花了很多时间寻找一种可以在不重新启动页面和不使用Jupyter笔记本/小部件的情况下更新Plotly Scattergeo(世界地图)的东西 基本上,我希望有一个“按钮”过滤器刷新我的数据集。例如,单击按钮执行函数foo,然后修改数据集,该数据集将反映在当前绘制的图形上 以下是一个最低限度的工作示例: import plotly.graph_objects as go from typing import Dict, List, Tuple data = [((-79.63059998, 4
过滤器
刷新我的数据集
。例如,单击按钮执行函数foo
,然后修改数据集
,该数据集将反映在当前绘制的图形上
以下是一个最低限度的工作示例:
import plotly.graph_objects as go
from typing import Dict, List, Tuple
data = [((-79.63059998, 43.67720032),(55.36439896, 25.25279999)),
((126.4509964, 37.46910095), (12.2388889, 41.8002778)),
((31.40559959, 30.12190056),(-0.461941, 51.4706))]
data = [ ((seg[0][1], seg[1][1]), (seg[0][0], seg[1][0])) for seg in data]
fig = go.Figure()
# generate all flight segments on a Scattergeo (world map)
for lat, lon in data:
fig.add_trace(
go.Scattergeo(
lat=lat,
lon=lon,
mode='lines',
line=dict(width=1, color='red')
),
)
# draw the plotly figure
fig.update_layout(
title_text='Flight Simulator',
showlegend=False,
geo=dict(
resolution=110,
showland=True,
showlakes=True,
landcolor='rgb(204, 204, 204)',
countrycolor='rgb(204, 204, 204)',
lakecolor='rgb(255, 255, 255)',
projection_type="equirectangular",
coastlinewidth=2,
lataxis=dict(
range=[-90, 90],
showgrid=True,
dtick=10
),
lonaxis=dict(
range=[-180, 180],
showgrid=True,
dtick=20
),
)
)
# adds the initial filters
fig.update_layout(
updatemenus=[
go.layout.Updatemenu(
active=0,
type="buttons",
direction="right",
buttons=list([
dict(label="Reset",
method="restyle",
args=[{"visible": [segment for segment in data]}]
),
dict(label="Filter",
method="restyle",
args=[{"visible": [segment for segment in data]}]
),
]),
pad={"r": 10, "t": 30, "b": 10},
showactive=True,
x=0.90,
xanchor="right",
y=1.15,
yanchor="top"
),
])
# display the figure to the screen
fig.show()
如果需要重新启动页面,是否可以在该localhost实例上的同一绘图上重新绘制