I am trying to draw a bar plot with matplotlib. the data set looks like this
I managed to get a bar plot of the count of 'GICS sector', and the code is
pd.value_counts(df['GICS Sector'],normalize=False).plot.bar()
# plt.hist(df['GICS Sector'])
plt.xlabel('sectors',fontsize=14)
plt.xticks(fontsize=12,rotation=90)
plt.title('Histogram of GICS Sectors',fontsize = 20)
plt.ylabel('count for sectors', fontsize=12)
plt.show()
The plot looks like this count of each sector.
For each sector, there are different 'GICS Sub Industry' as you can see in the data frame I printed out. For example, 'Health Care' sector has 'Health Care Equipment' and 'Pharmaceuticals' as sun industries. I would like to change each sector to a stacked bar plot of different sub industries which belongs to the same GICS sector. I could get a bar plot for each sector separately, code here
categories = df['GICS Sector'].unique()
for c in categories:
print(c,":",df[df['GICS Sector']==c]['GICS Sub Industry'].nunique())
for c in categories:
pd.value_counts(df[df['GICS Sector']==c]['GICS Sub Industry'],normalize=False).plot.bar()
plt.ylabel('count for sub industries')
plt.title(c)
plt.show()
bar plot when for sector 'industrials'
but I am not able to stack them together and combine them all into one plot.
Any suggestion helps! Thanks!