【发布时间】:2021-10-07 12:53:42
【问题描述】:
我正在使用 Plotly Dash 创建一个仪表板,其中包含在公共 x 轴上带有条形图和折线图的图。当我运行它时,代码运行良好,但是当我从下拉列表中选择不同的选项来更改图表时,某些选项的一些条形图会随机丢失。 这是一个运行良好的示例。perfectly fine image
这是一个示例,当我从下拉列表中选择不同的选项时,图中的条形消失了。
我不确定出了什么问题。我检查了缺失条的数据是否丢失,但它在那里,当我将鼠标悬停在图中缺失的条区域上时,它也向我显示了那里的值,但没有显示条。作为参考,这是我的代码……
trace1 = go.Scatter(
mode='lines+markers+text',
x = df1['Date'],
y = df1['AVG'],
name="Avg time(mins)",
text=df1['AVG'],
textposition='bottom right',
textfont_color='black',
marker_color='blue',
opacity=1
)
trace2 = go.Bar(
x = df1['Date'],
y = df1['Id_Count'],
name="Count",
ids=df1['Id_Count'],
text=df1['Id_Count'],
textposition='inside',
insidetextfont_color='#45FC03',
hoverinfo='x+y',
yaxis='y2',
marker_color ='#180702',
marker_line_width=1.5,
marker_line_color='black',
opacity=0.72
)
data1 = [trace1, trace2]
layout1 = go.Layout(
title_text='Day wise stats',
title_font_color='#45FC03',
width=1300,
height=400,
yaxis=dict(
side = 'right'
),
yaxis2=dict(
overlaying='y',
anchor='y3',
)
)
fig1 = go.Figure(data=data1, layout=layout1)
fig1.update_layout(template='plotly_dark',
plot_bgcolor='#F0E199', paper_bgcolor='#282522', margin_l=50, margin_t=80, margin_b=60)
fig1.update_xaxes(showgrid=False, zeroline=False)
fig1.update_yaxes(showgrid=False, zeroline=False)
拜托,如果能提供任何解决此问题的方法,我们将不胜感激。
【问题讨论】:
-
没有什么可以显示您的过滤方式。我怀疑条形图丢失是因为过滤后的数据框中的关联值是 NaN。这不是随机的,而是基于数据/如何完成过滤的功能