df = pd.DataFrame(np.random.randn(20, 4)*10, columns=['cafe', 'diet', 'cloth', 'film'])
df_unusual = pd.DataFrame({
'cafe':[-10,72],
'diet':[82,100],
'cloth':[-9,99],
'film':[110,90],
}) # 为了增加一些异常值
df = df.append(df_unusual, ignore_index=True)
plt.figure()
df.boxplot(
vert=False,
widths=0.2,
showfliers=False,
showbox=False,
whiskerprops= {'linestyle':'dotted','color':'c3c7cb'}
)
for i, c_name in enumerate(df.columns):
q1, q2, q3 = df[c_name].quantile(0.25), df[c_name].quantile(0.5), df[c_name].quantile(0.75)
plt.barh(i+1, width=q3-q1, left=q1, height=0.2, color='#c3c7cb')
plt.barh(i+1, width=q2-q1, left=q1, height=0.2, color='#30c2d0')
plt.scatter(df[c_name], np.ones(df.shape[0]) + i, s=5, color='grey')
plt.
scatter画出来的点一部分被bar给遮住了,怎么破?
最新推荐文章于 2023-04-29 13:31:53 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)