gpt4 book ai didi

python - 如何在 plotly (python) 中的刻度标签和图形之间添加空格?

转载 作者:太空宇宙 更新时间:2023-11-03 13:27:40 24 4
gpt4 key购买 nike

如果我使用 plotly 创建水平条形图,则每个条形的标签都紧靠图形。我想在标签和图表之间添加一些空格/填充/边距。我怎样才能做到这一点?

例子:

import plotly.offline as py
import plotly.graph_objs as go
labels = ['Alice','Bob','Carl']
vals = [2,5,4]

data = [go.Bar(x=vals, y=labels, orientation='h')]

fig = go.Figure(data)
py.iplot(fig)

enter image description here

最佳答案

只需在margin 中使用参数pad。检查文档中的示例 here .代码:

import plotly.offline as py
import plotly.graph_objs as go

labels = ['Alice','Bob','Carl']
vals = [2,5,4]

data = [go.Bar(x=vals, y=labels, orientation='h')]

layout = go.Layout(
margin=dict(
pad=20
),
title = 'hbar',
)
fig = go.Figure(data=data,layout=layout)

py.plot(fig, filename='horizontal-bar.html')

plotly 应该是这样的: Your plot

关于python - 如何在 plotly (python) 中的刻度标签和图形之间添加空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52391451/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com