#24 Histogram with a boxplot on top | seaborn

This chart is mainly based on seaborn but necessitates matplotlib as well, to split the graphic window in 2 parts. If you need to learn how to custom individual charts, visit the histogram and boxplot sections.

# Import library and dataset
import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')

# Cut the window in 2 parts
f, (ax_box, ax_hist) = plt.subplots(2, sharex=True, gridspec_kw={"height_ratios": (.15, .85)})

# Add a graph in each part
sns.boxplot(df["sepal_length"], ax=ax_box)
sns.distplot(df["sepal_length"], ax=ax_hist)

# Remove x axis name for the boxplot

  • Sponsors

  • Leave a Reply

    Your email address will not be published.