Box plot using graph objects class

If Plotly Express does not accommodate a good starting point, then it is also possible to use the more generic go.Box class from plotly.graph_objects. Box plot is a consistent way of distribution of data which are based on five main component shown below:

  • Minimum : the lowest data point excluding any outliers.
  • Maximum : the largest data point excluding any outliers.
  • Median (Q2 / 50th Percentile) : the middle value of the dataset.
  • First quartile (Q1 / 25th Percentile) : also known as the lower quartile qn(0.25), is the median of the lower half of the dataset.
  • Third quartile (Q3 / 75th Percentile) : also known as the upper quartile qn(0.75), is the median of the upper half of the dataset.

Syntax: class plotly.graph_objects.Box(arg=None, alignmentgroup=None, boxmean=None, boxpoints=None, customdata=None, customdatasrc=None, dx=None, dy=None, fillcolor=None, hoverinfo=None, hoverinfosrc=None, hoverlabel=None, hoveron=None, hovertemplate=None, hovertemplatesrc=None, hovertext=None, hovertextsrc=None, ids=None, idssrc=None, jitter=None, legendgroup=None, line=None, lowerfence=None, lowerfencesrc=None, marker=None, mean=None, meansrc=None, median=None, mediansrc=None, meta=None, metasrc=None, name=None, notched=None, notchspan=None, notchspansrc=None, notchwidth=None, offsetgroup=None, opacity=None, orientation=None, pointpos=None, q1=None, q1src=None, q3=None, q3src=None, quartilemethod=None, sd=None, sdsrc=None, selected=None, selectedpoints=None, showlegend=None, stream=None, text=None, textsrc=None, uid=None, uirevision=None, unselected=None, upperfence=None, upperfencesrc=None, visible=None, whiskerwidth=None, width=None, x=None, x0=None, xaxis=None, xcalendar=None, xsrc=None, y=None, y0=None, yaxis=None, ycalendar=None, ysrc=None, **kwargs)

Parameters: 
x: Sets the x sample data or coordinates. See overview for more info. 
y: Sets the y sample data or coordinates. See overview for more info. 
hoverinfo: Determines which trace information appear on hover. 
marker: Instance or dict with compatible properties. 
mean: Sets the mean values. 
median: Sets the median values. 
 

Example:

Python3




import plotly.graph_objects as px
import numpy as np
 
 
# creating random data through randomint
# function of numpy.random
np.random.seed(42)
 
random_y1= np.random.randint(1,101,100)
random_y2= np.random.randint(1,101,100)
 
x = ['A', 'B', 'C', 'D']
 
plot = px.Figure()
 
plot.add_trace(px.Box(y=random_y1))
plot.add_trace(px.Box(y=random_y2))
 
plot.show()


Output:

Box plot in Plotly using graph_objects class

Plotly is a Python library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library.

Similar Reads

Box plot using graph objects class

If Plotly Express does not accommodate a good starting point, then it is also possible to use the more generic go.Box class from plotly.graph_objects. Box plot is a consistent way of distribution of data which are based on five main component shown below:...

Horizontal Box Plot

...

Finding Mean and Standard Deviation

The horizontal box plot is a box plot in which the x-variable and y-values are shown horizontally in the graph. It can be created by passing the x argument of the box plot....

Changing Algorithms for Quartiles

...

Showing The Underlying Data

The mean and standard deviation of the data plotted by boxplot can be found using the boxmean parameter. It can take two values –...

Contact Us