Python 绘图下拉输出图表
我似乎弄不懂文件。基本上我想创建一个下拉菜单,每个选择输出一个不同的图表。这是一个MRE。plotly.express作为px导入Python 绘图下拉输出图表,python,plotly,dropdown,Python,Plotly,Dropdown,我似乎弄不懂文件。基本上我想创建一个下拉菜单,每个选择输出一个不同的图表。这是一个MRE。plotly.express作为px导入 race = pd.read_csv('https://github.com/ngpsu22/Ed_Debt-vs.-UBI/raw/main/race_debt_ubi') education = pd.read_csv('https://github.com/ngpsu22/Ed_Debt-vs.-UBI/raw/main/education_debt_ubi'
race = pd.read_csv('https://github.com/ngpsu22/Ed_Debt-vs.-UBI/raw/main/race_debt_ubi')
education = pd.read_csv('https://github.com/ngpsu22/Ed_Debt-vs.-UBI/raw/main/education_debt_ubi')
income = pd.read_csv('https://github.com/ngpsu22/Ed_Debt-vs.-UBI/raw/main/income_debt_ubi')
fig_race = px.bar(race, x='race', y='percent_has_debt', text='percent_has_debt')
fig_education = px.bar(education, y='percent_has_debt', text='percent_has_debt')
fig_income = px.bar(income, y='percent_has_debt', text='percent_has_debt')
基本上,我想创建一个下拉菜单['race'、'education'、'income'],输出相应的图表。我已将您的数据制成一个图表,您可以在“plotly”中的“go”下拉菜单中选择。默认设置是显示所有值。我在官方和官方的帮助下修改了它
这太棒了,正是我想要的。有没有办法让它在没有“无”选项的情况下工作?你可以从按钮列表中删除“dict(label='none'…)”。当我尝试删除它时…默认跟踪仍然拥有所有图表,直到我单击其中一个结果,然后它们才正确更新。我错了。“无”应该是“可见的”:所有内容都应该是错误的。我想知道如何在加载时不显示任何内容。是的,我也不知道。谢谢你的尝试
import plotly.graph_objects as go
import pandas as pd
race = pd.read_csv('https://github.com/ngpsu22/Ed_Debt-vs.-UBI/raw/main/race_debt_ubi')
education = pd.read_csv('https://github.com/ngpsu22/Ed_Debt-vs.-UBI/raw/main/education_debt_ubi')
income = pd.read_csv('https://github.com/ngpsu22/Ed_Debt-vs.-UBI/raw/main/income_debt_ubi')
fig = go.Figure()
fig.add_trace(go.Bar(x=race['race'], y=race['percent_has_debt'], name='race'))
fig.add_trace(go.Bar(x=[0,1,2,3], y=education['percent_has_debt'], name='education'))
fig.add_trace(go.Bar(x=[0,1,2,3,4,5], y=income['percent_has_debt'], name='income'))
fig.update_layout(
updatemenus=[go.layout.Updatemenu(
active=0,
buttons=list([
dict(label="None",
method="update",
args=[{'visible':[False,False,False]},
{'title':'AL','showlegend':True}]),
dict(label="race",
method="update",
args=[{'visible':[True,False,False]},
{'title':'RACE','showlegend':True}]),
dict(label="education",
method="update",
args=[{'visible':[False,True,False]},
{'title':'EDUCATION','showlegend':True}]),
dict(label="income",
method="update",
args=[{'visible':[False,False,True]},
{'title':'INCOME','showlegend':True}]),
]
))])
fig.show()