Week 12 Bar Plots

There seems to be an issue with barplots in matplotlib.pyplot, The heights of the bars seems to be getting messed up completely. and all i get is a sequence of Bars in ascending order, but the data isn’t like that, check below…The data is for the date 27 July, 2020 from the same url from which json was imported in video

Please Help

Hi @keshav0801,
Have you tried using some other way of plotting with the same data?(Like doing bar plots directly using pandas or seaborn) As this seems to be an unusual issue.

Same topic but different concern.
I have added comments against code for concern.

fig = plt.gcf();
fig.set_size_inches(15, 6);
plt.bar(df_.index, df_.Confirmed, color='Orange');
plt.bar(df_.index, df_.Recovered, bottom=df_.Confirmed, color='Green');
plt.bar(df_.index, df_.Deceased, bottom=df_.Confirmed + df_.Recovered, color='Red');

for i, val in enumerate(df_.index):
    y = df_.loc[val].sum() + 100 # By adding 100 here actual count is increasing by 100 however our motive is to just place it little above the bar
    x = i
    plt.text(x, y + 100, str(y), ha="center"); # Shouldn't it be placed here?


1 Like

Yes, you’re right… for plotting purpose, passing y+100 to the plot would have been better, as it won’t reflect the changes in our original dataframe.

1 Like