import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import pandas as pd
import seaborn as sns
from mpl_ornaments.titles import set_title_and_subtitle

fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(7.5,6))

#1
df = pd.read_csv('data/iris.csv', comment='#')

#2
sns.scatterplot(data=df, x='SepalLengthCm', y='PetalLengthCm',
                size='PetalWidthCm', hue='Species', sizes=(50,800),
                alpha=0.4, ax=ax)

#3
handles, labels = ax.get_legend_handles_labels()

#4
blank_handle, blank_label = Line2D([0], [0], linewidth=0), ''
for i in range(3):
    handles.insert(4,blank_handle); labels.insert(4,blank_label)

#5
labels = [s.replace('PetalWidthCm', 'Petal width [cm]') for s in labels]

#6
for h in handles[-6::]:
    h.set_color('lightgrey'); h.set_edgecolor('grey')

#7
ax.legend(handles=handles, labels=labels, ncols=2, borderpad=1.2)

#8
ax.set_xlabel('Sepal length [cm]'); ax.set_ylabel('Petal length [cm]') 
ax.spines[['right', 'top']].set_visible(False)
ax.grid(which='major')

title = 'Iris sepal length, petal length and petal width'
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=35)

fig.savefig('charts/scatter-bubble-plot.png', bbox_inches='tight', 
            dpi=300)