熊猫图是否有断轴?

时间:2021-01-30 09:43:21

标签: python pandas matplotlib

对于 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

1 个答案:

答案 0 :(得分:1)

您可以使用 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