Matplotlib box plot fliers not showing
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:
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:
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:
You might not see fliers if the flier marker was set to None
. The page you linked to has a for flier in bp['fliers']:
loop, which sets the flier marker style, color and alpha:
import numpy as npimport matplotlib.pyplot as pltnp.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 instancefig = plt.figure(1, figsize=(9, 6))# Create an axes instanceax = fig.add_subplot(111)# Create the boxplotbp = ax.boxplot(data_to_plot, showfliers=True)for flier in bp['fliers']: flier.set(marker='o', color='#e7298a', alpha=0.5)plt.show()
yields