【发布时间】:2020-08-25 06:13:39
【问题描述】:
我试图创建一个条形图,我想在其中钻取区域,然后查看 3 年范围内各个城市的人口。 基本上我发现了这个 https://community.plotly.com/t/drill-down-function-for-graphs-embedded-in-dash-app/12290/9 但我无法实施
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
from dash.dependencies import Output, Input, State
import numpy as np
import pandas as pd
import plotly.figure_factory as ff
from pandas import read_excel
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
# app = dash.Dash()
file_name = 'samplePop1.csv'
df = pd.read_csv(file_name)
print(df.head())
colors = {
'black' : '#000000',
'text' : '#696969',
'plot_color' : '#C0C0C0',
'white' : '#FFFFF'
}
app.layout = html.Div ([
dcc.Graph(
id = 'bar-chart',
figure = { 'data' :
[
{'x' : df['Name'],'y':df['Population Census 1991'],'type':'bar','name':'Population Census 1991'},
{'x' : df['Name'],'y':df['Population Census 2001'],'type':'bar','name':'Population Census 2001'},
{'x' : df['Name'],'y':df['Population Census 2011'],'type':'bar','name':'Population Census 2011'}
],
'layout' : {
'plot_bgcolor' : colors['white'],
'paper_bgcolor' : colors['white'],
'font' : {
'color' : colors['white']
},
'title' : 'Bar Chart',
'orientation':'h'
}
}
)
])
if __name__ == '__main__':
app.run_server(port = '8080' , debug ='True')
条形图应首先显示 3 年范围内的人口区域,当我点击一个区域时 它应显示地区明智的比较。 还有另一个基本图表,他们将在区域和城市之间单击 2 次,以显示 3 年的人口范围,它应该更清楚地显示值,它应该是可滚动的。
链接到 csv 文件 https://github.com/9192gks/mapbox/blob/master/samplePop1.csv
【问题讨论】:
标签: python python-3.x plotly plotly-dash plotly-python