如何在python的绘图框中设置框宽?

时间:2014-10-23 17:51:32

标签: python plotly

我目前有以下内容;

y = time_h
time_box = Box(
    y=y,
    name='Time (hours)',
    boxmean=True,
    marker=Marker(color='green'),
    boxpoints='all',
    jitter=0.5,
    pointpos=-2.0
)
layout = Layout(
    title='Time Box',
)
fig = Figure(data=Data([time_box]), layout=layout)
plotly.image.save_as(fig, os.path.join(output_images, 'time_box.png'))

这将呈现以下图表:

enter image description here

这个框太宽了,我还没能在文档中找到任何内容。

2 个答案:

答案 0 :(得分:6)

您还可以使用boxgap(以及boxgroupgap,以便在Layout内的不同x位置(如此处:https://plot.ly/python/box-plots/#Grouped-Box-Plot)属性时存在多个框。更多详情:Plotly Python Reference - Box Gap

确保您拥有1.3.1或更高版本。 $ pip install plotly --upgrade

import plotly.plotly as py
from plotly.graph_objs import *

data = Data([
    Box(
        y=[0, 1, 1, 2, 3, 5, 8, 13, 21],
        boxpoints='all',
        jitter=0.3,
        pointpos=-1.8
    )
])

layout = Layout(
    boxgap=0.5
)

fig = Figure(data=data, layout=layout)
plot_url = py.plot(fig, filename='box-plot-with-gap')

https://plot.ly/~chris/3048 Simple Plotly box-plot with group gap

更多例子:

boxgap=0boxgroupgap=0boxgap=0, boxgroupgap=0

boxgap=0.25boxgroupgap=0enter image description here

boxgap=0boxgroupgap=0.25enter image description here

boxgap=0.25boxgroupgap=0.25enter image description here

在Workspace中使用这些参数也很有帮助,您可以在其中修改图形的每个参数: enter image description here

答案 1 :(得分:1)

试试这个

layout = Layout(
    title='Time Box',
    width=500,
    height=500
)

这应创建500x500图表

有关详细信息,请参阅https://plot.ly/python/setting-graph-size/