0
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
%matplotlib notebook
plt.figure(figsize=(12, 6))
CasData.pivot(index='year', columns='CasualtyNumber', values='People').plot(kind='bar')
plt.title('Casualties per year')
plt.xlabel('Year', fontsize=5)
plt.ylabel('Number of Casualties')
plt.show()

My plot bar graph using matplotlib.pyplot isn't showing. I don't know why but my bar graph isn't showing. I've tried different ways. If someone could help me out please. I'd appreciate it. Thank you.

Zephyr
  • 11,891
  • 53
  • 45
  • 80
Bea
  • 1
  • 1
  • 4
    [Please don't post an image of code](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Add the code as text. – BigBen Sep 11 '20 at 20:10
  • Post your code in a formal way. It may help you find the exact response or the answer. Good attempt and try to make your way more formal. Thanks and good luck. – Hashan Malawana Sep 11 '20 at 20:29

2 Answers2

0

Remove the line %matplotlib notebook. It is overriding the previous line (these two lines are setting the backend). inline returns static plots, notebook is used for interactivity.

You also do not need the plt.show() line. This is taken care of by the inline backend.

This answer explains more about the backends: https://stackoverflow.com/a/43028034/6709902

J.Warren
  • 728
  • 1
  • 4
  • 14
0

I'm not really sure about your code as it seems incomplete but if you're using pivot I assumed you're pulling the data from a ".csv" file.

import matplotlib as mpl
import matplotlib.pyplot as plt
import pandas as pd

%matplotlib notebook

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

CasData.pivot_table(index='year', columns='CasualtyNumber', values='People').plot(kind='bar')
plt.title('Casualties per year')
plt.xlabel('Year',fontsize='5')
plt.ylabel('Number of Casualties')
plt.show()

Image for my plot

You need to provide the data in order to plot something and I don't see you providing any.

Souhailhimself
  • 221
  • 1
  • 10