3

我正在尝试使用破折号和绘图生成一个散点图框,当我在标记内指定一个符号(例如“正方形”)时,它不会在生成地图时呈现。我正在使用回调函数,我尝试了几个符号,但没有一个有效,但圆圈标记。我有什么明显的遗漏吗?这是一个最小的示例,要运行它,您需要一个 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')

在此先感谢,我仍然不知道我是否遗漏了一些明显的东西。

4

1 回答 1

2

我发现问题主要出在两件事上:

  • 在标记中混合一个符号(正方形),具有默认大小和颜色(不支持此功能)。
  • Scattermapbox 不支持符号(正方形),您可以在此处找到列表:支持的符号!.

我还打开了一个 github 问题,您可以在其中找到更多信息github 问题

于 2017-12-05T21:16:36.897 回答