# How to Create a Box Plot in Plotly Python

In this post, you will learn How to create a Box Plot in Plotly Python.

## 1 . Create a Box Plot using Plotly Express –

Read a dataset to work with.

import pandas as pd
import plotly.graph_objects as go
import plotly.express as px

df.head()

To create a Box plot in Plotly express, we use the px.box() method.

fig = px.box(df, y="Runs")
fig.show()

If a column name is given as x argument, a box plot is drawn for each value of x.

fig = px.box(df, x="Team", y="Runs")
fig.show()

You can also use the color parameter to further segments the data.

fig = px.box(df, x="Team", y="Runs", color="Nationality")
fig.show()

If you want You can also show the underlying data using the points parameter. By default it shows the outliers but you can also show all the data by setting points=’all’

fig = px.box(df, x="Nationality", y="Runs", points="all")
fig.show()

You can also create styled box plot

fig = px.box(df, x="Nationality", y="Runs", notched=True)
fig.show()

## 2 . Create a Box Plot with plotly graph objects –

To create a box plot with plotly graph objects, we use the go.Box() method.

fig =go.Figure()
fig.update_layout(yaxis_title="Runs")
fig.show()

### Multiple box plot –

indian = df[df['Nationality']=="Indian"]
overseas = df[df['Nationality']=="Overseas"]

fig =go.Figure()
fig.update_layout(xaxis_title="Nationality", yaxis_title="Runs")
fig.show()

### Horizontal Box Plot –

indian = df[df['Nationality']=="Indian"]
overseas = df[df['Nationality']=="Overseas"]

fig =go.Figure()
fig.show()
indian = df[df['Nationality']=="Indian"]
fig.show()