Box Plots

Box Plots#

We can generate box plots using .plot.box() or .boxplot(). The default settings visualize the distribution of values within each column.

Back to our random number DataFrame, this time with five columns.

import pandas as pd, numpy as np # import statements
df = pd.DataFrame(np.random.randn(10, 5), columns=['A', 'B', 'C', 'D', 'E']) # create random data
df.plot.box() # box plot
<Axes: >
../_images/2f093a9c3efe864b9adb74147cecf3d55d1a6f673bd4a2d16e2109603b842c79.png

We can add colors to our box plot using the color keyword.

df.plot.box(color='blue') # set color
<Axes: >
../_images/ab9d6f485920953af30d8cf00d5a59cecc5140b16266c3e0f45d7dd3bfcfe449.png

We can also use a dictionary with key-value pairs for each component of our box plot.

color = {"boxes": "DarkGreen", "whiskers": "DarkOrange", "medians": "DarkBlue", "caps": "Gray",} # color dictionary
df.plot.box(color=color, sym="r+") # draw plot and specify colors and outlier symbol using keyword argument or kwarg
<Axes: >
../_images/3cecd5322a40482a9bd92695e7582d4a780e5511b4090667b46e478b74dc0187.png

Additional Resources#

For more on box plots: