8

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:

enter image description here

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

2 Answers 2

13

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

Make sure that you have version 1.3.1 or higher. $ 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

Some more examples:

boxgap=0 and boxgroupgap=0: boxgap=0, boxgroupgap=0

boxgap=0.25 and boxgroupgap=0: enter image description here

boxgap=0 and boxgroupgap=0.25: enter image description here

boxgap=0.25 and boxgroupgap=0.25: enter image description here

It's also helpful to play around with these parameters in the Workspace, where you can modify every parameter of the graphs: enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

This works great for keeping Candlestick boxes together too. fig = go.Figure(data) fig.update_layout(boxgap=0, boxgroupgap=0)
1

Try this

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

This should create a 500x500 graph

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

1 Comment

I was thinking about changing the actual element in the graph, not the size of the whole graph, but this solution has worked well. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.