Correlogram

Wine Quality Features

Oenology correlogram of chemical properties by wine type

Output
Wine Quality Features
Python
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np

np.random.seed(123)

n = 160
wine_type = np.random.choice(['Red', 'White', 'Rosé'], n)
data = {
    'Alcohol (%)': np.where(wine_type == 'Red', np.random.normal(13, 0.8, n),
                           np.where(wine_type == 'White', np.random.normal(11, 0.7, n), np.random.normal(12, 0.6, n))),
    'Acidity': np.where(wine_type == 'White', np.random.normal(6.5, 0.8, n),
                       np.where(wine_type == 'Red', np.random.normal(5.5, 0.6, n), np.random.normal(6, 0.5, n))),
    'Residual Sugar': np.where(wine_type == 'White', np.random.normal(6, 3, n),
                              np.where(wine_type == 'Rosé', np.random.normal(8, 4, n), np.random.normal(2.5, 1, n))),
    'pH': np.random.normal(3.3, 0.15, n),
    'Type': wine_type
}
df = pd.DataFrame(data)

sns.set_style("whitegrid", {'axes.facecolor': '#ffffff', 'figure.facecolor': '#ffffff', 'grid.color': '#eeeeee'})

palette = {'Red': '#9C2007', 'White': '#F5D327', 'Rosé': '#F527B0'}

g = sns.pairplot(
    df,
    hue='Type',
    palette=palette,
    height=2,
    kind='reg',
    diag_kind='hist',
    markers=['o', '^', 's'],
    plot_kws={'scatter_kws': {'alpha': 0.65, 's': 50, 'edgecolor': 'white', 'linewidths': 0.6}, 'line_kws': {'linewidth': 2}},
    diag_kws={'alpha': 0.6, 'edgecolor': 'white', 'linewidth': 0.5}
)

g.fig.set_facecolor('#ffffff')
for ax in g.axes.flat:
    if ax:
        ax.set_facecolor('#ffffff')
        for spine in ax.spines.values():
            spine.set_color('#dddddd')
        ax.tick_params(colors='#666666')
        ax.xaxis.label.set_color('#333333')
        ax.yaxis.label.set_color('#333333')

g.fig.suptitle('Wine Chemical Composition', fontsize=14, fontweight='bold', color='#1a1a1a', y=1.02)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support