How do you set the box width in a plotly box in python?

2024/10/15 18:24:29

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.

Answer

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

https://en.xdnf.cn/q/69255.html

Related Q&A

how do you install django older version using easy_install?

I just broke my environment because of django 1.3. None of my sites are able to run. So, i decided to use virtualenv to set virtual environment with different python version as well as django.But, seem…

Whats difference between findall() and iterfind() of xml.etree.ElementTree

I write a program using just like belowfrom xml.etree.ElementTree import ETxmlroot = ET.fromstring([my xml content])for element in xmlroot.iterfind(".//mytag"):do some thingit works fine on m…

How to convert string dataframe column to datetime as format with year and week?

Sample Data:Week Price 2011-31 1.58 2011-32 1.9 2011-33 1.9 2011-34 1.9I have a dataframe like above and I wanna convert Week column type from string to datetime.My Code:data[Date_Time…

Tensorflow - ValueError: Shape must be rank 1 but is rank 0 for ParseExample/ParseExample

I have a .tfrecords file of the Ubuntu Dialog Corpus. I am trying to read in the whole dataset so that I can split the contexts and utterances into batches. Using tf.parse_single_example I was able to …

Navigating Multi-Dimensional JSON arrays in Python

Im trying to figure out how to query a JSON array in Python. Could someone show me how to do a simple search and print through a fairly complex array please?The example Im using is here: http://eu.bat…

Numpy, apply a list of functions along array dimension

I have a list of functions of the type:func_list = [lambda x: function1(input),lambda x: function2(input),lambda x: function3(input),lambda x: x]and an array of shape [4, 200, 200, 1] (a batch of image…

Database first Django models

In ASP.NET there is entity framework or something called "database first," where entities are generated from an existing database. Is there something similar for Django? I usually work with …

How to use pythons Structural Pattern Matching to test built in types?

Im trying to use SPM to determine if a certain type is an int or an str. The following code: from typing import Typedef main(type_to_match: Type):match type_to_match:case str():print("This is a St…

Importing app when using Alembic raises ImportError

I am trying to study how to use alembic in flask, I want to import a method in flask app:tree . . ├── README.md ├── alembic │ ├── README │ ├── env.py │ ├── env.pyc │ ├── s…

Git add through python subprocess

I am trying to run git commands through python subprocess. I do this by calling the git.exe in the cmd directory of github.I managed to get most commands working (init, remote, status) but i get an err…