我正在准备晶须间隔为[2,98]
的方块图。问题是,我正在处理空气质量数据,并且有大量的数据点,因此异常值占据了整个数据,掩盖了箱线图。我只想绘制最大和最小异常值,并尝试了Matplotlib boxplot show only max and min fliers中的方法,但是,我收到一条错误消息,上面写着TypeError: 'AxesSubplot' object is not subscriptable
这是我的密码:
fig,ax = plt.subplots(1, figsize=(8,6))
g = sns.boxplot(data=mda8, orient='v', width = 0.7, whis = (2,98))
fliers = g['fliers']
for fly in fliers:
fdata=fly.get_data
fly.set_data([fdata[0][0],fdata[0][-1],fdata[1][0],fdata[1][-1]])
xvalues = ['Niland', 'El Centro', 'Calexico']
plt.xticks(np.arange(3), xvalues, fontsize=12)
ax.set_ylabel('Ozone MDA8 (ppb)',fontsize=15)
ax.set_ylim(0,105)
plt.show()
以下是一些示例数据:
mda8 = pd.DataFrame({
'T1':[35.000000, 32.125000, 32.000000, 35.250000, 28.875000, 28.500000, 29.375000, 25.125000, 34.166667, 35.250000],
'T2':[28.375, 30.750, 33.250, 34.000, 32.875, 30.250, 29.875, 100.409, 29.625, 1.232],
'T3':[34.250, 102.232, 28.250, 33.000, 27.625, 21.500, 28.375, 30.250, 3.454, 33.750]})
我只需要绘制最大和最小异常值的帮助,除了我在这里尝试的方法外,我还愿意使用另一种方法
编辑这是指向我的csv文件的链接https://drive.google.com/file/d/1E3A0UAYCbSN53JXtfsbrA4i_Phci_JWf/view?usp=sharing
一种可能的办法可以是:
通过传递
showfliers = False
参数来隐藏由seaborn.boxplot
绘制的异常值:获取每列的异常值列表,找到最大值和最小值,并仅绘制它们:
完整代码
编辑
处理您提供的数据,如果我按原样绘制:
我得到:
在上面的代码中,我更改了参数
showfliers = False
,以隐藏异常值。然后,正如JohanC在评论中所建议的,绘制异常值的一种更简单的方法是为每列绘制最小值和最大值:
完整代码
相关问题 更多 >
编程相关推荐