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

时间:2022-02-28 07:31:16

I currently have the following;

我目前有以下内容;

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

This renders the following graph:

这将呈现以下图表:

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

The box is too wide and I haven't been able to find anything in the docs.

框太宽,我无法在文档中找到任何内容。

2 个解决方案

#1


6  

You can also mess around with the boxgap (and boxgroupgap for when there are multiple boxes at different x locations, like here: https://plot.ly/python/box-plots/#Grouped-Box-Plot) property inside Layout. More details here: Plotly Python Reference - Box Gap

您还可以使用boxgap(以及boxgroupgap,以便在布局中的不同x位置有多个框时,如此处:https://plot.ly/python/box-plots/#Grouped-Box-Plot)。更多细节:Plotly Python Reference - Box Gap

Make sure that you have version 1.3.1 or higher. $ pip install plotly --upgrade

确保您具有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 如何在python的绘图框中设置框宽?

https://plot.ly/~chris/3048

Some more examples:

更多例子:

boxgap=0 and boxgroupgap=0: 如何在python的绘图框中设置框宽?

boxgap = 0和boxgroupgap = 0:

boxgap=0.25 and boxgroupgap=0: 如何在python的绘图框中设置框宽?

boxgap = 0.25和boxgroupgap = 0:

boxgap=0 and boxgroupgap=0.25: 如何在python的绘图框中设置框宽?

boxgap = 0和boxgroupgap = 0.25:

boxgap=0.25 and boxgroupgap=0.25: 如何在python的绘图框中设置框宽?

boxgap = 0.25和boxgroupgap = 0.25:

It's also helpful to play around with these parameters in the Workspace, where you can modify every parameter of the graphs: 如何在python的绘图框中设置框宽?

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

#2


1  

Try this

尝试这个

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

This should create a 500x500 graph

这应创建500x500图表

See https://plot.ly/python/setting-graph-size/ for more info

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

#1


6  

You can also mess around with the boxgap (and boxgroupgap for when there are multiple boxes at different x locations, like here: https://plot.ly/python/box-plots/#Grouped-Box-Plot) property inside Layout. More details here: Plotly Python Reference - Box Gap

您还可以使用boxgap(以及boxgroupgap,以便在布局中的不同x位置有多个框时,如此处:https://plot.ly/python/box-plots/#Grouped-Box-Plot)。更多细节:Plotly Python Reference - Box Gap

Make sure that you have version 1.3.1 or higher. $ pip install plotly --upgrade

确保您具有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 如何在python的绘图框中设置框宽?

https://plot.ly/~chris/3048

Some more examples:

更多例子:

boxgap=0 and boxgroupgap=0: 如何在python的绘图框中设置框宽?

boxgap = 0和boxgroupgap = 0:

boxgap=0.25 and boxgroupgap=0: 如何在python的绘图框中设置框宽?

boxgap = 0.25和boxgroupgap = 0:

boxgap=0 and boxgroupgap=0.25: 如何在python的绘图框中设置框宽?

boxgap = 0和boxgroupgap = 0.25:

boxgap=0.25 and boxgroupgap=0.25: 如何在python的绘图框中设置框宽?

boxgap = 0.25和boxgroupgap = 0.25:

It's also helpful to play around with these parameters in the Workspace, where you can modify every parameter of the graphs: 如何在python的绘图框中设置框宽?

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

#2


1  

Try this

尝试这个

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

This should create a 500x500 graph

这应创建500x500图表

See https://plot.ly/python/setting-graph-size/ for more info

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