Skip to main content
 首页 » 编程设计

python之Pandas 箱线图上出现奇怪的标记

2025年02月15日12zhenyulu

我用下面的代码创建了一个箱线图,看起来像下图,但我不明白为什么大西洋海岸和太平洋海岸箱子上方会出现一些奇怪的加号标记。为什么会出现这些“+”标记?

boxplot_2015 = data_2015.boxplot(column = 'LCOE', by = 'Coastal Region', return_type = 'axes') 
plt.title('LCOE by Region') 
plt.suptitle('') 
plt.xlabel('Region') 
plt.ylabel('LCOE ($/MWh)') 
plt.grid(False) 
plt.show() 

请您参考如下方法:

那些是传单。如果您不喜欢它们,请使用 showfliers=False

docs

fliers: points representing data that extend beyond the whiskers (fliers).

调整你的代码

boxplot_2015 = data_2015.boxplot( 
    column = 'LCOE', by = 'Coastal Region', 
    return_type = 'axes', showfliers=False) 
plt.title('LCOE by Region') 
plt.suptitle('') 
plt.xlabel('Region') 
plt.ylabel('LCOE ($/MWh)') 
plt.grid(False) 
plt.show() 

示范

df = pd.DataFrame(np.random.randn(1000, 4), columns=list('ABCD')) 
 
fig, axes = plt.subplots(1, 2) 
df.boxplot(ax=axes[0]) 
axes[0].set_title('With Fliers') 
df.boxplot(ax=axes[1], showfliers=False) 
axes[1].set_title('Without Fliers')