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

2024-10-03 17:24:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前有以下情况:

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

箱子太宽了,我在文件里找不到任何东西。在


Tags: nameboxtruetimefig情况greenmarker
2条回答

当在不同的x位置有多个框时,您也可以使用boxgap(和boxgroupgap),比如在Layout内有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/3048Simple Plotly box-plot with group gap

还有一些例子:

boxgap=0和{}: boxgap=0, boxgroupgap=0

boxgap=0.25和{}: enter image description here

boxgap=0和{}: enter image description here

boxgap=0.25和{}: ^{5美元

您还可以在工作区的每个参数中修改以下参数: enter image description here

试试这个

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

这将创建一个500x500图形

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

相关问题 更多 >