使用plotly绘制

时间:2018-12-19 09:45:12

标签: python layout plotly plotly-dash choropleth

我是Plotly的新手。我正在尝试使用此工具绘制一个Choropleth贴图。我将数据存储在数据库中,并试图在地图中显示其中的一些数据。 首先,我启动我的das应用程序:app = dash.Dash() 连接到数据库后,我将执行以下代码:

#Load dataframes
df = pd.read_sql('SELECT * FROM Companies_Public', con=db_connection)

#Choropleth map
app.layaout = html.Div([
    dcc.Graph(
        id = 'Map',
        figure={
            'data': [ dict(
                    type = 'choropleth',
                    locations = df['ISOCountry'],
                    z = sum(df['FinalPointsPerDemography']),
                    text = df['CountryName'],
                    colorscale = [[0,"rgb(5, 10, 172)"],[0.35,"rgb(40, 60, 190)"],[0.5,"rgb(70, 100, 245)"],\
                        [0.6,"rgb(90, 120, 245)"],[0.7,"rgb(106, 137, 247)"],[1,"rgb(220, 220, 220)"]],
                    autocolorscale = False,
                    reversescale = True,
                    marker = dict(
                        line = dict (
                            color = 'rgb(180,180,180)',
                            width = 0.5
                        ) ),
                    colorbar = dict(
                        autotick = False,
                        tickprefix = '$',
                        title = 'Points<br>'),
                  ) ],

            'layout': go.Layout(
                title = 'Points by Company per Demography',
                geo = dict(
                    showframe = False,
                    showcoastlines = False,
                    projection = dict(
                        type = 'Mercator'
                    )
                )
            )
        }
    )
])

# Add the server clause:
if __name__ == '__main__':
    app.run_server()

我在控制台中收到下一条消息:

dash.exceptions.NoLayoutException:在调用None时布局是run_server。在运行服务器之前,请确保设置应用程序的layout属性。

下图显示了df的结构: df structure

0 个答案:

没有答案