微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

剧情下拉输出图表

如何解决剧情下拉输出图表

我似乎无法弄清楚文档。基本上,我想创建一个下拉菜单,并且每个选择都输出不同的图表。这是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')
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,text='percent_has_debt')
fig_income = px.bar(income,text='percent_has_debt')

基本上,我想创建一个['race','education','income']下拉菜单,以输出相应的图表。

解决方法

我已经将您的数据制作成图表,您可以在下拉菜单中选择“ plotly”中的“ go”。默认为显示所有值。我在官方referencethis site的帮助下对其进行了修改。

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,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",args=[{'visible':[True,{'title':'RACE',dict(label="education",True,{'title':'EDUCATION',dict(label="income",True]},{'title':'INCOME',]
))])


fig.show()

enter image description here

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?