【发布时间】:2021-10-27 05:51:15
【问题描述】:
我正在尝试制作一个带有多选功能的数据应用程序来可视化数据。我想为在多选选项中选择的客户端显示一个包含三个参数的分组条形图。但是,无论我选择哪个客户端,图表都以与原始数据相同的顺序显示,即即使我在多选中选择了第 7 个客户端,我仍然会得到数据框中第一行的图表。 代码如下:
data = load_data()
st.markdown('### Client Selection, Offers and Joinings')
clients= data['Client']
clients1=clients.to_list()
options=st.multiselect('Client List',clients1)
st.write(data)
selections=data['selections']
offers=data['offers']
joinings=data['joinings']
fig1 = go.Figure()
fig1.add_trace(go.Bar(
x=options,
y=selections,
name='Selections',
marker_color='indianred'
))
fig1.add_trace(go.Bar(
x=options,
y=offers,
name='Offers',
marker_color='lightsalmon'
))
fig1.add_trace(go.Bar(
x=options,
y=joinings,
name='joinings',
marker_color='indianred'
))
# Here we modify the tickangle of the xaxis, resulting in rotated labels.
fig1.update_layout(barmode='group', xaxis_tickangle=-45)
st.plotly_chart(fig1)
有人可以帮我解决这个问题吗? 谢谢
【问题讨论】:
标签: pandas dataframe numpy plotly streamlit