如何更改第一个数据点和 Y 轴之间的默认距离?

How to change the default distance between the first data point and the Y axis?

默认情况下,我的绘图加载方式如下,我想减小 Y 轴与图表中第一个数据点之间的距离(距离以红色显示) 默认值:

所以它看起来像这样 期望:

我是这样生成这张图的:

def revenue_graph_update(input_first):
input_first = int(input_first)
fig = go.Figure()
revenue = _revenue.tail(input_first)
revenue_total = go.Scatter(
    x = revenue.index,
    y = revenue['Airtime Sum'] + revenue['Data Sum'],
    mode = 'lines+markers',
    name = 'Total',
    opacity = 0.8,
    #marker_color = 'orange',
    line_shape = 'spline',
)

revenue_air = go.Scatter(
    x = revenue.index,
    y = revenue['Airtime Sum'],
    mode = 'lines+markers',
    name = 'Airtime',
    opacity = 0.8, 
    #marker_color = 'gold', 
    line_shape = 'spline'
)

revenue_data = go.Scatter(
    x = revenue.index,
    y = revenue['Data Sum'],
    mode = 'lines+markers', 
    name = 'Data',
    opacity = 0.8, 
    #marker_color = 'ivory', 
    line_shape = 'spline'
)

fig.add_trace(revenue_total)
fig.add_trace(revenue_air)
fig.add_trace(revenue_data)

fig.update_layout(
    title = 'Revenue (Advance Fee Recovered)',
    xaxis_title = 'Date',
    yaxis_title = 'Revenue (IRR)',
    plot_bgcolor="#FFF",
    xaxis_gridcolor='whitesmoke',
    yaxis_gridcolor='whitesmoke',
)
return dcc.Graph(figure=fig, config= {'displaylogo': False})

您可以使用 fig.update_xaxes(range=(start, end)) 指定 x 轴范围。要严格限制,您可以将 startend 设置为数据集的 min()max() 值。在你的情况下:

start = revenue.index.min()
end = revenue.index.max()
fig.update_xaxes(range=(start, end))