import matplotlib.pyplot as plt
import pandas as pd 
from mpl_ornaments.titles import set_title_and_subtitle

df = pd.read_csv('data/iris.csv', comment='#')

#1
features = {'SepalLengthCm': 'Sepal length [cm]', 
            'PetalLengthCm': 'Petal length [cm]',
            'SepalWidthCm': 'Sepal width [cm]',
            'PetalWidthCm': 'Petal width [cm]'}

#2
fig, axes = plt.subplots(nrows=len(features), ncols=len(features),
                         figsize=(8,8))

#3
for i, (ifeat_name, ifeat_label) in enumerate(features.items()):
    for j, (jfeat_name, jfeat_label) in enumerate(features.items()):      

#4
        x, y = df[ifeat_name], df[jfeat_name]
        axes[i,j].scatter(x=x, y=y, edgecolors='black', linewidths=0.5)
        
#5
        if i == len(features)-1:
            axes[i,j].set_xlabel(jfeat_label)
        if j == 0:
            axes[i,j].set_ylabel(ifeat_label)

#6
        axes[i,j].spines[['right', 'top']].set_visible(False)      

title = 'Iris dataset: scatter plot matrix'
subtitle = ('Source: The Iris Dataset. UCI Machine Learning Repository '
            '(via Kaggle)')
set_title_and_subtitle(fig=fig, title=title, subtitle=subtitle, 
                       alignment='left', h_offset=30, v_offset=20)

fig.savefig('charts/scatter-plot-matrix.png', dpi=300,
            bbox_inches='tight')