有没有断轴的Pandas阴谋?

2024-05-13 11:58:54 发布

您现在位置:Python中文网/ 问答频道 /正文

就像matplotlibbroken axes一样

有人会想做这样的事情:

import pandas as pd
import seaborn as sns

kuk = sns.load_dataset('car_crashes')

kuk.groupby("abbrev").mean().plot()

如果存在异常值(是的,我知道我可以一行一行、一类一类地做,但与一行相比…),我不希望底部填充太多重叠值

enter image description here


Tags: importpandasmatplotlibasloadseaborncar事情
1条回答
网友
1楼 · 发布于 2024-05-13 11:58:54

可以使用ax=参数指定熊猫用来打印的轴。因此,只需在每个轴上以正确的比例绘制两次数据即可

例如,使用纯matplotlib(添加所有内容以创建断轴效果):

kuk = sns.load_dataset('car_crashes')

fig, (ax1, ax2) = plt.subplots(2,1, sharex=True)
kuk.groupby("abbrev").mean().plot(ax=ax1)
kuk.groupby("abbrev").mean().plot(ax=ax2, legend=False)

ax2.set_ylim(top=250)
ax1.set_ylim(bottom=500)

enter image description here

相关问题 更多 >