79395173

Date: 2025-01-28 21:06:20
Score: 1.5
Natty:
Report link

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))

example boxplot with whiskers indicated min and max values

(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 boxplot with whiskers removed showing just the interquartile range

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)
Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @miradulo's
  • Low reputation (0.5):
Posted by: Rachel W