Box Plot
A Box Plot is also known as Whisker plot is created to display the summary of the set of data values having properties like minimum, first quartile, median, third quartile and maximum. In the box plot, a box is created from the first quartile to the third quartile, a vertical line is also there which goes through the box at the median. Here x-axis denotes the data to be plotted while the y-axis shows the frequency distribution. It can be created using the px.box() method
Syntax:
plotly.express.box(data_frame=None, x=None, y=None, color=None, facet_row=None, facet_col=None, title=None, template=None, width=None, height=None, **kwargs)
Example:
Python3
import plotly.express as px # using the dataset df = px.data.tips() # plotting the boxplot fig = px.box(df, x = "day" , y = "tip" ) # showing the plot fig.show() |
Output:
Let’s see various customizations that can be used on boxplots –
- color: used to assign color to marks
- facet_row: assign marks to facetted subplots in the vertical direction
- facet_col: assign marks to facetted subplots in the horizontal direction
- boxmode: One of ‘group’ or ‘overlay’ In ‘overlay’ mode, boxes are on drawn top of one another. In ‘group’ mode, boxes are placed beside each other.
- notched: If True, boxes are drawn with notches
Example:
Python3
import plotly.express as px # using the dataset df = px.data.tips() # plotting the boxplot fig = px.box(df, x = "day" , y = "tip" , color = 'sex' , facet_row = 'time' , boxmode = 'group' , notched = True ) # showing the plot fig.show() |
Output:
Using Plotly for Interactive Data Visualization in Python
Plotly is an open-source module of Python which is used for data visualization and supports various graphs like line charts, scatter plots, bar charts, histograms, area plot, etc. In this article, we will see how to plot a basic chart with plotly and also how to make a plot interactive. But before starting you might be wondering why there is a need to learn plotly, so let’s have a look at it.