0
$\begingroup$

I am using some python code from kaggle that plots a bar graph. However, when I run it, it does not display the graph. When I run it in the IDE I get the following output:

<matplotlib.axes._subplots.AxesSubplot object at 0x1200b9ba8> <matplotlib.axes._subplots.AxesSubplot object at 0x1200b9ba8> <matplotlib.axes._subplots.AxesSubplot object at 0x1200b9ba8>

I have used the .show() method but nothing seems to work.

Here is the link to the code that I am using:

Code

I also have it directly in the question:

import numpy as np
import pandas as pd 
from matplotlib import pyplot as plt
import matplotlib
from sklearn.linear_model import LinearRegression

# Input data files are available in the "../input/" directory.
# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory

#from subprocess import check_output
#print(check_output(["ls", "../input"]).decode("utf8"))

# Any results you write to the current directory are saved as output.

frame=pd.read_csv('Project_Airplane_Crashes_and_Fatalities_Since_1908.csv',sep=',')
matplotlib.rcParams['figure.figsize'] = (12.0, 8.0)

operator = frame[['Operator','Fatalities']].groupby('Operator').agg(['sum','count'])

fig_ops,((ax1, ax2), (ax3, ax4))=plt.subplots(2,2,sharex=True)
accidents = operator['Fatalities','count'].sort_values(ascending=False)
totalacc = accidents.sum()
accprop = accidents/totalacc
accidents.head(10).plot(kind='bar',title='Accidents by Operator',ax=ax1,grid=True,rot=90)
accprop.head(10).plot(kind='bar',title='Proportion of Total Accidents',ax=ax2,grid=True,rot=90)

fatalities = operator['Fatalities','sum'].sort_values(ascending=False)
fatalities.head(10).plot(kind='bar',title='Fatalities by Operator',ax=ax3,grid=True,rot=90)
totalfatal = fatalities.sum()
fatalprop = fatalities/totalfatal
#print(fatalprop)
fatalprop.head(10).plot(kind='bar',title='Proportion of total Fatalities',ax=ax4,grid=True,rot=90)

Any help would be greatly appreciated.

$\endgroup$
1

1 Answer 1

1
$\begingroup$

I have gotten the answer to my question since I keep searching for solution. I got the solution here enter link description here

By StefanM

So all I needed and should have done is to simply do plt.show() and I was typing fatalprop.head(10).show() Thank you

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.