我正在尝试使用破折号和图形生成散点图框,当我在标记内指定符号(例如“方形”)时,它在生成地图时不会渲染。 我正在使用回调函数,我尝试了几个符号,其中没有一个符号,但圆圈标记。 有什么明显的东西让我失踪吗? 这是一个最小的例子,要运行它,你需要一个mapbox令牌。
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import datetime as dt
app = dash.Dash()
mapbox_access_token = 'YOUR_MAPBOX_TOKEN_HERE'
app.layout = html.Div(children=[
html.H1('Dashboard'),
dcc.DatePickerRange(id='fecha',
start_date=dt.datetime.today() - dt.timedelta(days=30),
end_date=dt.datetime.today()
),
html.Center(dcc.Graph(
id='mapa',
figure={
'data': [
go.Scattermapbox(
lat=[],
lon=[],
)
],
'layout': go.Layout(
autosize=False,
width=1300,
height=800,
hovermode='closest',
showlegend=False,
mapbox=dict(
accesstoken=mapbox_access_token,
bearing=0,
center=dict(
lat=-32,
lon=-70
),
pitch=0,
zoom=5,
),
)
})
,)
])
@app.callback(
dash.dependencies.Output('mapa', 'figure'),
[dash.dependencies.Input('fecha', 'start_date'),
dash.dependencies.Input('fecha', 'end_date')
])
def update_graph(inicio,fin):
Data = [go.Scattermapbox(
name='square',
lat=[-31,-30],
lon=[-71,-71],
marker = dict(
symbol='square',
size = 8,
opacity = 0.8,
color='grey'
),
text = np.array(['square1','square2'])),
go.Scattermapbox(
name='circle',
lat=[-31,-30],
lon=[-72,-72],
marker = dict(
symbol='circle',
size = 8,
opacity = 0.8,
color='grey'
),
text = ['circle1','circle2'])]
figure={
'data': Data,
'layout': go.Layout(
title='Visitas',
autosize=False,
width=1300,
height=800,
hovermode='closest',
showlegend=True,
mapbox=dict(
accesstoken=mapbox_access_token,
bearing=0,
center=dict(
lat=-30.5,
lon=-72
),
pitch=0,
zoom=5,
),
)
}
return figure
if __name__ == '__main__':
app.run_server(host= '0.0.0.0',port=9999)
我尝试制作相同的地图框而没有破折号(即只是情节),并且它再次失败,所以这不是一个破折号问题,这是我如何用剧情制作地图(为此你需要一个阴谋帐户):
import plotly.graph_objs as go
import plotly.plotly as py
mapbox_access_token = 'YOUR_TOKEN_HERE'
Data = [go.Scattermapbox(
name='square',
lat=[-31,-30],
lon=[-71,-71],
marker = dict(
symbol='square',
size = 8,
opacity = 0.8,
color='grey'
),
text = ['square1','square2']),
go.Scattermapbox(
name='circle',
lat=[-31,-30],
lon=[-72,-72],
marker = dict(
symbol='circle',
size = 8,
opacity = 0.8,
color='grey'
),
text = ['circle1','circle2'])]
figure={
'data': Data,
'layout': go.Layout(
title='Visitas',
autosize=False,
width=1300,
height=800,
hovermode='closest',
showlegend=True,
mapbox=dict(
accesstoken=mapbox_access_token,
bearing=0,
center=dict(
lat=-30.5,
lon=-72
),
pitch=0,
zoom=5,
),
)
}
py.iplot(figure, filename='Broken fig')
在此先感谢,我仍然不知道我是否遗漏了一些明显的东西。
答案 0 :(得分:0)
我发现问题主要来自两件事:
我还打开了一个github问题,您可以在其中找到更多信息github issue