大家好,我在条形图中比较不同种族的人口。我已经成功地创建了我的图表,但想要一个区域的下拉菜单。 条形图图像
这是我的代码,但是我无法协调下拉菜单。任何人都可以帮忙吗?excel数据:excel
import plotly.graph_objects as go
from plotly.offline import plot
import pandas as pd
import plotly.express as px
import pandas as pd #(version 1.0.0)
import plotly #(version 4.5.4) pip install plotly==4.5.4
import plotly.express as px
import dash #(version 1.9.1) pip install dash==1.9.1
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
app = dash.Dash(__name__)
raw_data= pd.read_csv('ethnicArea.csv')
data= raw_data[:len(raw_data)-1][['Ethnicity(%)', 'East', 'East Midlands', 'London', 'North East', 'North West', 'South East', 'South West', 'Wales', 'West Midlands', 'Yorkshire and The Humber']]
ethnicArea = list(data.columns)[1:]
fig_data=[]
for i in range(len(data.columns)-1):
a = ethnicArea[i]
b = list(data.iloc[:,0])
c = list(data.iloc[:,i+1])
print(a)
print(b)
print(c)
fig_data.append(go.Bar(name = a, x = b, y = c))
fig = go.Figure(fig_data)
fig.update_layout(barmode='group', title_text="Black vs White Population By Area (UK)", title_font_family="Times New Roman",title_font_color="black",
xaxis_title="Ethnicity group",yaxis_title="Population %",legend_title="Area (UK)", font_size=18)
plot(fig, filename="plot1.html")
app.layout = html.Div([
html.Div([
dcc.Graph(id='our_graph')
],className='nine columns'),
html.Div([
html.Br(),
html.Div(id='output_data'),
html.Br(),
html.Label(['Choose column:'],style={'font-weight': 'bold', "text-align": "center"}),
dcc.Dropdown(id='my_dropdown',
options=[
{'label': 'East', 'value': 'East'},
{'label': 'East Midlands', 'value': 'East Midlands'},
{'label': 'London', 'value': 'London'},
