While their Joy Division inspired t-shirts and posters have given some people the impression that they’re not a serious visualization tool, ridgeline plots are an effective way to get a general sense of distributional differences between groups in a dataset.
But while they’re pretty enough to appear on the seaborn logo; seaborn does not bother to include an api for them. The sole ridgeline example in the seaborn gallery relies on looping through a facetgrid which is hardly more elegant than just doing it in matplotlib.
Seaborn has an obvious bias towards the violin plot for distributional comparisons despite the violin plot being less informative and less attractive than the ridge plot. Luckily there are enough tools in the violin plot api that we can torture it until it generates the desired output.
Here is the fairly self-explanatory ridge_plot function.
mpg = sns.load_dataset("mpg")# Get common makes and format labelsmpg["make"] = mpg["name"].str.split(" ").str[0].str.title()mpg = mpg.groupby("make").filter(lambda x: len(x) >10)# Sort by horsepower rangehp_range = mpg.groupby("make")["horsepower"].agg(lambda x: x.max() - x.min()).sort_values()mpg["make"] = pd.Categorical(mpg["make"], categories=hp_range.index, ordered=True)mpg = mpg.sort_values("make", ascending=False)ridge_plot( mpg,"horsepower","make", density_norm="width", color="#6ea0b1",).set(title="American manufacturers offer a wider range of horsepowers", xlabel="Horsepower")plt.show()