My Work
My Work

Reputation: 2508

Are there broken axis for pandas plot?

As it is for matplotlib or broken axes.

Eg. one would want to do something like this:

import pandas as pd
import seaborn as sns

kuk = sns.load_dataset('car_crashes')

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

and would not want to have the bottom filled with too many overlapping values if there is an outlier (and yes, I know I can do it line by line and category by category but compared to the one liner...).

enter image description here

Upvotes: 0

Views: 636

Answers (1)

Diziet Asahi
Diziet Asahi

Reputation: 40707

You can specify which Axes pandas uses to plot using the ax= parameter. It is therefore just a matter of plotting your data twice with the correct scale on each axes.

For instance, using pure matplotlib (add in all the stuff to create the broken axes effect):

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

Upvotes: 1

Related Questions