使用 go.Bar() 时如何消除堆叠条之间的水平间隙?

How can I get rid of horizontal gaps between stacked bars when using go.Bar()?

这是 Plotly 文档中的示例:

import plotly.graph_objects as go
fig = go.Figure(data=[
    go.Bar(name='SF Zoo', x=['giraffes', 'orangutans', 'monkeys'], y=[20, 14, 23]),
    go.Bar(name='LA Zoo', x=['giraffes', 'orangutans', 'monkeys'], y=[12, 18, 29])
])
fig.update_layout(barmode='stack')

在他们的网站上看起来是这样的:

这里看起来像这样:

如何消除 monkeys 列中的微小间隙?

这些不是间隙,而是线条,颜色设置为'#636efa'。您可以通过 运行:

忽略它们
fig.update_traces(marker = dict(line = dict(color = 'rgba(0,0,0,0)')))

或者只是:

fig.update_traces(marker_line_color =  'rgba(0,0,0,0)')

情节

完整代码:

import plotly.graph_objects as go
fig = go.Figure(data=[
    go.Bar(name='SF Zoo', x=['giraffes', 'orangutans', 'monkeys'], y=[20, 14, 23]),
    go.Bar(name='LA Zoo', x=['giraffes', 'orangutans', 'monkeys'], y=[12, 18, 29])
])

fig.update_layout(barmode='stack')
# fig.update_traces(marker = dict(line = dict(color = 'rgba(0,0,0,0)')))
fig.update_traces(marker_line_color =  'rgba(0,0,0,0)')
fig.show()