我正在使用以下代码使用plotly 生成分组堆叠条形图。我想减少分组条之间的间隙。我怎样才能实现这个目标?特别是,我想让条形彼此相邻,之间几乎没有间隙。
rand_list = np.random.rand(30) # update this with original
df = pd.DataFrame(
dict(
week=[1.2,1.2,1.3,1.3,1.6,1.6,1.7,1.7,4.4,4.4] * 3,
layout=["abc","abc","def","def", "ghi", "ghi"] * 5,
response=["0", "1"] * 15,
cnt= list(rand_list),
)
)
print(df)
fig = go.Figure()
fig.update_layout(
template="simple_white",
xaxis=dict(title_text="x-label"),
yaxis=dict(title_text="y-label", showticklabels=False),
barmode="stack",
)
colors = ["#2A66DE", "#FFC32B"]
for r, c in zip(df.response.unique(), colors):
plot_df = df[df.response == r]
fig.add_trace(
go.Bar(x=[plot_df.week, plot_df.layout], y=plot_df.cnt, name=r, marker_color=c, width=0.2),
)
fig