To update @miradulo's great answer, the whis=range
syntax was deprecated staring in matplotlib 3.3
. The matplotlib 3.3+ way of forcing whiskers to cover the entire range of data is:
df.boxplot(grid=False, figsize=(9, 4), whis=(0, 100))
(docs for matplotlib.axes.Axes.boxplot
)
Alternately, you can remove whiskers all together and just show the interquartile range by combining whis=0
with the showfliers
and showcaps
arguments:
df.boxplot(grid=False, figsize=(9, 4), whis=0, showfliers=False, showcaps=False)
Example data:
import pandas as pd
example_data = {
2013: [1.09, 1.73, 2.23, 2.69], 2014: [0.97, 1.68, 2.00, 2.35],
2015: [1.04, 1.28, 1.85, 2.11], 2016: [0.86, 1.14, 2.12, 2.25],
2017: [1.08, 2.26, 2.44, 2.57]
}
df = pd.DataFrame(example_data)