I have just started learning python and I am using the Titanic data set to practice
I am not able to create a grouped bar chart and it it giving me an error 'incompatible sizes: argument 'height' must be length 2 or scalar'
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("Titanic/train.csv")
top_five = df.head(5)
print(top_five)
column_no = df.columns
print(column_no)
female_count = len([p for p in df["Sex"] if p == 'female'])
male_count = len([i for i in df["Sex"] if i == 'male'])
have_survived= len([m for m in df["Survived"] if m == 1])
not_survived = len([n for n in df["Survived"] if n == 0])
plt.bar([0],female_count, color ='b')
plt.bar([1],male_count,color = 'y')
plt.xticks([0+0.2,1+0.2],['females','males'])
plt.show()
plt.bar([0],not_survived, color ='r')
plt.bar([1],have_survived, color ='g')
plt.xticks([0+0.2,1+0.2],['not_survived','have_survived'])
plt.show()
it works fine until here and I get two individual charts
Instead i want one chart that displays bars for male and female and color code the bars based on survival.
This does not seem to work
N = 2
index = np.arange(N)
bar_width = 0.35
plt.bar(index, have_survived, bar_width, color ='b')
plt.bar(index + bar_width, not_survived, bar_width,color ='r',)
plt.xticks([0+0.2,1+0.2],['females','males'])
plt.legend()
Thanks in advance!!