如何在没有半条的情况下从周六到周日干净地制作这张图?

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

我正在尝试创建一个条形图来表示一周内的数据。一切看起来都很好,但第一个和最后一个小节(周六)似乎被切成两半。我的代码如下。我该如何解决这个问题?

Graph Image

nf = px.bar(dmt, x='date', y='Nutrition', title="Nutrition Scores", width=0.5)
nf.update_xaxes({'range': ('2024-06-08', '2024-06-15')}, tickmode='linear', 
tickformat='%a <br> %d', title=None)
nf.update_yaxes(title='Nutrition')
nf.update_layout(title_x=0.5, plot_bgcolor="white", paper_bgcolor="white")
nf.update_traces(marker_color='#1e439d')
python plotly data-science plotly-dash
1个回答
0
投票

您可以使用参数沿 X 轴边缘添加额外空间

nf = px.bar(dmt, x='date', y='Nutrition', title="Nutrition Scores", width=0.5)

nf.update_xaxes(
    range=['2024-06-08', '2024-06-15'], 
    tickmode='linear'
)

nf.update_layout(xaxis=dict(range=['2024-06-07', '2024-06-16']))
nf.update_yaxes(title='Nutrition')
nf.update_layout(title_x=0.5, plot_bgcolor="white", paper_bgcolor="white")
nf.update_traces(marker_color='#1e439d')
© www.soinside.com 2019 - 2024. All rights reserved.