import matplotlib.pyplot as plt
import pandas as pd

data = pd.read_csv('titanic.csv')

Class = data[['Pclass']].values
Survived = data[['Survived']].values

FirstClass = 0
SecondClass = 0 
ThirdClass = 0
FirstClassSurvived = 0
FirstClassDied = 0
SecondClassSurvived = 0 
SecondClassDied = 0
ThirdClassSurvived = 0 
ThirdClassDied = 0

for i in range(0, len(Class)):
  if Class[i] == 1:
    FirstClass += 1
    if Survived[i] == 1: 
       FirstClassSurvived += 1
    else:
       FirstClassDied += 1

  elif Class[i] == 2:
    SecondClass += 1
    if Survived[i] == 1: 
       SecondClassSurvived += 1
    else:
       SecondClassDied += 1

  elif Class[i] == 3:
    ThirdClass += 1
    if Survived[i] == 1: 
       ThirdClassSurvived += 1
    else:
       ThirdClassDied += 1
       

# Data to plot
labels = '1st Class', '2nd Class', '3rd Class'
sizes = [FirstClass, SecondClass, ThirdClass]
colors = ['gold', 'yellowgreen', 'lightcoral']
explode = (0.1, 0, 0)  # explode 1st slice
plt.title("Passenger Class Assignment")
# Plot
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
autopct='%1.1f%%', shadow=True, startangle=140)

plt.show()

sizes = [FirstClassSurvived, SecondClassSurvived, ThirdClassSurvived]
colors = ['gold', 'yellowgreen', 'lightcoral']
explode = (0.1, 0, 0)  # explode 1st slice
plt.title("Surviving Passengers by Class Assignment")
# Plot
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
autopct='%1.1f%%', shadow=True, startangle=140)

plt.show()

sizes = [FirstClassDied, SecondClassDied, ThirdClassDied]
colors = ['gold', 'yellowgreen', 'lightcoral']
explode = (0.1, 0, 0)  # explode 1st slice
plt.title("Passenger Deaths by Class Assignment")
# Plot
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
autopct='%1.1f%%', shadow=True, startangle=140)

plt.show()
