Matplotlib box plot fliers not showing

maths_student15 picture maths_student15 · Mar 6, 2015 · Viewed 15.4k times · Source

I was wondering if anyone had an issue with Matplotlib's box plot fliers not showing?

I literally copy-pasted this example here into a python script: http://blog.bharatbhole.com/creating-boxplots-with-matplotlib/

...but the box plot fliers (outliers) are not showing. Does anyone know why I might not be seeing them? Sorry if this is a silly question, but I cannot for the life of me figure out why it doesn't work.

## Create data
np.random.seed(10)
collectn_1 = np.random.normal(100, 10, 200)
collectn_2 = np.random.normal(80, 30, 200)
collectn_3 = np.random.normal(90, 20, 200)
collectn_4 = np.random.normal(70, 25, 200)

## combine these different collections into a list    
data_to_plot = [collectn_1, collectn_2, collectn_3, collectn_4]

# Create a figure instance
fig = plt.figure(1, figsize=(9, 6))

# Create an axes instance
ax = fig.add_subplot(111)

# Create the boxplot
bp = ax.boxplot(data_to_plot)

I also tried adding showfliers=True to the last line of that script, but it's still not working.

This is what I get as an output:

enter image description here

Answer

Puggie picture Puggie · Apr 9, 2015

From the look of your plot, it seems you have imported the seaborn module. There is an issue with matplotlib boxplot fliers not showing up when seaborn is imported, even when fliers are explicitly enabled. Your code seem to be working fine when seaborn is not imported:

Boxplot with fliers, no seaborn

When seaborn is imported, you could do the following:

Solution 1:

Assuming you have imported seaborn like this:

import seaborn as sns

you can use the seaborn boxplot function:

sns.boxplot(data_to_plot, ax=ax)

resulting in:

Seaborn boxplot with fliers

Solution 2:

In case you want to keep using the matplotlib boxplot function (from Automatic (whisker-sensitive) ylim in boxplots):

ax.boxplot(data_to_plot, sym='k.')

resulting in:

Matplotlib boxplot with fliers