我有两组正在处理的数据,我想使用plotly在条形图中显示它们(数据示例如下所示)。第一个此程式码会产生下列图形:
我想在每个名称的两个方法之间添加一个空格(在每个值中的两个值的方法一和方法二之间添加空格)。我试过使用offsetgroup,但似乎不起作用。任何帮助将不胜感激。
offsetgroup
dzjeubhm1#
在绘图中调整条间距的唯一函数是条间距和组内间距的类型。因此,您可以通过在条间距和组内间距之间插入一个空值图形来强制调整条间距。
fig.update_layout(barmode='group', bargroupgap=0.2)
fig = go.Figure() fig.add_trace(go.Bar( x = names, y = values1, legendgroup="group", legendgrouptitle_text="method one", name="first" )) fig.add_trace(go.Bar( x=names, y=values2, legendgroup="group", name="second" )) # add bar plot(null data) fig.add_trace(go.Bar( x=names, y=np.full((1,51),np.NaN), showlegend=False, )) fig.add_trace(go.Bar( x=names, y=values3, legendgroup="group2", legendgrouptitle_text="method two", name="first" )) fig.add_trace(go.Bar( x=names, y=values4, legendgroup="group2", name="second" )) fig.update_layout(barmode='group')#, bargroupgap=0.2 fig.update_traces(texttemplate='%{y:.2}', textposition='inside') fig.show()
hmae6n7t2#
我觉得你应该使用一个支线剧情:点击此链接,查看示例。Subplots
2条答案
按热度按时间dzjeubhm1#
在绘图中调整条间距的唯一函数是条间距和组内间距的类型。因此,您可以通过在条间距和组内间距之间插入一个空值图形来强制调整条间距。
hmae6n7t2#
我觉得你应该使用一个支线剧情:点击此链接,查看示例。Subplots