绘图瀑布图未显示总数

问题描述 投票:0回答:1

我有一些数据希望用瀑布图表示。但是,它确实绘制了总计列。情况是这样的:

x_values=['2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021', '2022', '2023', 'i alt']
y_values=[4559, 3080, 2988, 2979, 6668, 6492, 3416, 6122, 7709, 2076, 4676, 50766]
wf_measure=['relative', 'relative', 'relative', 'relative', 'relative', 'relative', 'relative', 'relative', 'relative', 'relative', 'relative', 'total']

fig2 = go.Figure(go.Waterfall(name = "", orientation = "v",
                            measure = wf_measure,
                            x = x_values,
                            textposition = "outside",
                            text = y_values,
                            y = y_values,
                            connector={"line": {"color": "black", "width": 1, "dash": "dot"}},
                            texttemplate='%{text:,.0f}M'))
        
fig2.update_layout(title = 'dette er en test',
                title_x=0.25,
                title_font=dict(size=16),
                xaxis_title="År",
                showlegend = False,
                height=450, 
                width=1020,
                plot_bgcolor='white',
                xaxis=dict(showgrid=True, gridcolor='lightgrey', gridwidth=0.5, tickvals=x_values),
                yaxis=dict(showgrid=True, gridcolor='lightgrey', gridwidth=0.5, tickformat='.0f'),
                shapes=[{'type':'line',
                            'x0':x_values[0],
                            'x1':x_values[-1],
                            'y0':0,
                            'y1':0,
                            'line':{'color':'grey','width':0.5,'dash':'dash'}}]
                )
        
fig2.update_traces(
    textfont=dict(size=10), 
    decreasing=dict(marker=dict(color='#e65a6d')), 
    increasing=dict(marker=dict(color='#a3dce8')), 
    totals=dict(marker=dict(color='#003755'))
    )

fig2.show()  

附件是输出png。有人有建议吗?

python plotly
1个回答
0
投票

您提供的代码在 Plotly 中成功创建了瀑布图,并且它确实包含处理“总计”列的逻辑。 您可以使用此方法从图表中删除“总计”列。

1。从 wf_measure 中删除“总计”值。 这会删除 y=0 处的水平线,该水平线通常用于指示瀑布图中的总值。 通过这些修改,图表将不再显示“总计”列或水平线。

这是更新后的代码的副本:

x_values=['2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021', '2022', '2023', 'i alt']
y_values=[4559, 3080, 2988, 2979, 6668, 6492, 3416, 6122, 7709, 2076, 4676, 50766]
wf_measure=['relative', 'relative', 'relative', 'relative', 'relative', 'relative', 'relative', 'relative', 'relative', 'relative', 'relative']  # 'total' removed

fig2 = go.Figure(go.Waterfall(name = "", orientation = "v",
                            measure = wf_measure,
                            x = x_values,
                            textposition = "outside",
                            text = y_values,
                            y = y_values,
                            connector={"line": {"color": "black", "width": 1, "dash": "dot"}},
                            texttemplate='%{text:,.0f}M'))
        
fig2.update_layout(title = 'dette er en test',
                title_x=0.25,
                title_font=dict(size=16),
                xaxis_title="År",
                showlegend = False,
                height=450, 
                width=1020,
                plot_bgcolor='white',
                xaxis=dict(showgrid=True, gridcolor='lightgrey', gridwidth=0.5, tickvals=x_values),
                yaxis=dict(showgrid=True, gridcolor='lightgrey', gridwidth=0.5, tickformat='.0f'),
                shapes=[{'type':'line',
                            'x0':x_values[0],
                            'x1':x_values[-1],
                            'y0':0,
                            'y1':0,
                            'line':{'color':'grey','width':0.5,'dash':'dash'}}]
                )
        
fig2.update_traces(
    textfont=dict(size=10), 
    decreasing=dict(marker=dict(color='#e65a6d')), 
    increasing=dict(marker=dict(color='#a3dce8')))  # 'totals' removed

fig2.show()
© www.soinside.com 2019 - 2024. All rights reserved.