Split Violin Plot for Diamond Cuts

Using the ‘diamonds’ dataset, plot a violin plot that showcases the distribution of prices, split to compare the distribution for ‘Fair’ and ‘Ideal’ cuts side by side.

Example Output:

Utilize sns.violinplot and use the split parameter.

import seaborn as sns
import matplotlib.pyplot as plt

def plot_advanced_violin():
    diamonds_data = sns.load_dataset('diamonds')
    filtered_data = diamonds_data[diamonds_data.cut.isin(['Fair', 'Ideal'])]
    sns.violinplot(x="cut", y="price", data=filtered_data, split=True)



© Let’s Data Science


Unlock AI & Data Science treasures. Log in!