Combining box plots and kernel density plots with violin plots

Violin plots combine box plots and kernel density plots or histograms in one type of plot. Seaborn and matplotlib both offer violin plots. We will use Seaborn in this recipe on z-scores of weather data. The z-scoring is not essential, but without it, the violins will be more spread out.

How to do it...

  1. Import the required libraries as follows:
    import seaborn as sns
    from dautil import data
    import matplotlib.pyplot as plt
  2. Load the weather data and calculate z-scores:
    df = data.Weather.load()
    zscores = (df - df.mean())/df.std()
  3. Plot a violin plot of the z-scores:
    %matplotlib inline
    plt.figure()
    plt.title('Weather Violin Plot')
    sns.violinplot(zscores.resample('M'))
    plt.ylabel('Z-scores')

    Refer ...

Get Python Data Analysis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.