[英]Remove repeated years from x-axis in plotly
I have draw a bar chart in plotly (python).我在 plotly (python) 中绘制了一个条形图。 The year value
2019
is repeated along y-axis.年份值
2019
沿 y 轴重复。 How can I display only one 2019
in the middle not others.如何在中间只显示一个
2019
而不是其他。
My code:我的代码:
a = pd.DataFrame(a.groupby(by=['Year', 'Vendor Name'])
['Spend'].sum())
fig_2 = px.bar(a, x='Year', y='Spend',
color='Vendor Name', barmode='stack', text='Spend')
fig_2.update_traces(marker_line_width=0)
fig_2.update_layout(
title="",
xaxis_title="",
yaxis_title="Total Spend",
legend_title="Vendor names",
height=450,
width=700,
)
you can do你可以做
a['year'] = a['date'].dt.year
gives the column with only the year part, the actual date column should be of datetime
though.给出只有年份部分的列,但实际日期列应该是
datetime
。 Then maybe you could do那么也许你可以做
fig2.update_xaxez(type="category")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.