如何在 plotly (python) 中添加刻度标签和图形之间的空间? [英] How do I add space between the tick labels and the graph in plotly (python)?

查看:48
本文介绍了如何在 plotly (python) 中添加刻度标签和图形之间的空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

示例:

import plotly.offline as py导入 plotly.graph_objs as go标签 = ['爱丽丝','鲍勃','卡尔']vals = [2,5,4]数据 = [go.Bar(x=vals, y=labels,orientation='h')]fig = go.Figure(数据)py.iplot(图)

解决方案

只需在margin中使用参数pad即可.检查文档

If I create a horizontal bar graph using plotly, the labels for each bar are right up against the graph. I'd like to add some space/pad/margin between the label and the graph. How can I do this?

Example:

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)

解决方案

Just use parameter pad in margin. Check example from docs here. Code:

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')

And plot should be looks something like that:

这篇关于如何在 plotly (python) 中添加刻度标签和图形之间的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆