繁体   English   中英

是否可以突出显示 px.scatter_mapbox plot 的一段?

[英]Is highlighting a segment of px.scatter_mapbox plot possible?

使用破折号图为散点线 plot 和散点图框创建占位符。

html.Div([
   html.Div(id='graphs', children=[
      dcc.Graph({'type':'graph', 'index':1}, figure=blank_fig('plotly_dark')),
      dcc.Graph({'type':'graph', 'index':1}, figure=blank_fig('plotly_dark'))]
])

这些数字是通过回调初始化的,如下所示,使用 Plotly Express:

fig1 = px.line(x=df.index.seconds, y=df.ft, labels={'x':'Elasped Time(seconds)', 'y':'feet'}, title="(feet)", template='plotly_dark')
fig2 = px.scatter_mapbox(df, lat='deg1', lon='deg2', zoom=zoom, height=800,
           text=['deltatime: {}'.format(i.total_seconds()) for i in df.index], 
           title=selected_values['report_type'], center=dict(lat=center[0], lon=center[1]))
fig2.update_layout(
    mapbox_style="white-bg",
    mapbox_layers=[{
        "below": 'traces',
        "sourcetype": "raster",
        "sourceattribution": "Low-Res Satellite Imagery",
        "source": [f"{self.map_host}/tiles/{{z}}/{{x}}/{{y}}.png"]
    }]
)
fig2.update_traces(mode='markers', marker=dict(size=2, color='white'), 
    hovertemplate='lat: %{lat}'+'<br>lon: %{lon}<br>'+'%{text}')

在图 1 的缩放操作期间,我通过回调获得了选定的范围。 有了这个选定的范围,我们就有了一个点列表,然后传递给update_traces()selectedpoints参数 function。目标是用红色突出显示那些选定的点,而不是整条线都涂成红色。

 # retrieved from the relayout input.  The xaxis is in seconds. 
 start = int(unique_data['xaxis.range[0]'])
 end = int(unique_data['xaxis.range[1]'])
 # using the above values we can then subselect the dataframe
 fig = get_figure_with('mapbox') # retrieves the figure for fig2
 selected_df = df[(df.index.seconds >= start) & (df.index.seconds <= end)]
 points = list(selected_df[['latitude_deg','longitude_deg']].itertuples(index=False, name=None))
 fig.update_traces(marker_color='Red', selectedpoints=points)

是否可以突出显示一段 mapbox plot? 例如下面plot的弯曲部分?

在此处输入图像描述

为此,我成功地使用px.line_mapbox() function。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM