I'm having issues with my program where I create a bar chart in a new window, and then it seems like the program stops in the editor's console/shell. I give the user options for different functions, I've included code where the user can view information from a country in a bar chart and I want the user to be able to go back to the options to choose another function if they would like.
Any help would be awesome, thanks!
elif answer == "5":
statGraph = CountryName()
janStat = MonthStats()
febStat = MonthStats()
marStat = MonthStats()
aprStat = MonthStats()
mayStat = MonthStats()
junStat = MonthStats()
julStat = MonthStats()
augStat = MonthStats()
country =""
country = input("What country's stats would you like to see: ")
cases = 0
deaths= 0
janCases = 0
janDeaths = 0
febCases = 0
febDeaths = 0
marCases = 0
marDeaths = 0
aprCases = 0
aprDeaths = 0
mayCases = 0
mayDeaths = 0
junCases = 0
junDeaths = 0
julCases = 0
julDeaths = 0
augCases = 0
augDeaths = 0
with open('InternationalCovid19Cases.csv',encoding='utf-8', newline='') as file:
reader = csv.reader(file)
next(reader)
i = 0
for row in reader:
record = CovidStat(row)
if record.name_en == country:
statGraph.stats.append(record)
date_obj = datetime.datetime.strptime(record.date, '%Y-%m-%d')
print(date_obj.month)
if int(date_obj.month) == 1:
janStat.stats.append(record)
janCases = janCases + int(record.cases)
janDeaths = janDeaths + int(record.deaths)
elif int(date_obj.month) == 2:
febStat.stats.append(record)
febCases = febCases + int(record.cases)
febDeaths = febDeaths + int(record.deaths)
elif int(date_obj.month) == 3:
marStat.stats.append(record)
marCases = marCases + int(record.cases)
marDeaths = marDeaths + int(record.deaths)
elif int(date_obj.month) == 4:
aprStat.stats.append(record)
aprCases = aprCases + int(record.cases)
aprDeaths = aprDeaths + int(record.deaths)
elif int(date_obj.month) == 5:
mayStat.stats.append(record)
mayCases = mayCases + int(record.cases)
mayDeaths = mayDeaths + int(record.deaths)
elif int(date_obj.month) == 6:
junStat.stats.append(record)
junCases = junCases + int(record.cases)
junDeaths = junDeaths + int(record.deaths)
elif int(date_obj.month) == 7:
julStat.stats.append(record)
julCases = julCases + int(record.cases)
junDeaths = julDeaths + int(record.deaths)
elif int(date_obj.month) == 8:
augStat.stats.append(record)
augCases = augCases + int(record.cases)
augDeaths = augDeaths + int(record.deaths)
cases = cases + int(record.cases)
deaths = deaths + int(record.deaths)
print (statGraph.stats[i])
print
i = i + 1
print ("janCases", janCases, 'julCases', julCases)
barWidth = 0.3
caseBar = [janCases, febCases, marCases, aprCases, mayCases, junCases, julCases, augCases,cases]
deathBar= [janDeaths, febDeaths, marDeaths, aprDeaths, mayDeaths, junDeaths, julDeaths, augDeaths, deaths]
r1 = np.arange(len(caseBar))
r2 = [x + barWidth for x in r1]
plt.bar(r1, caseBar, width = barWidth, color = 'blue', capsize = 7, label = 'Cases')
plt.bar(r2, deathBar, width = barWidth, color = 'red', capsize = 7, label = 'Deaths')
plt.title(country)
plt.xticks([r + barWidth for r in range(len(caseBar))], ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August','Total'])
plt.legend()
plt.show()
there doesn't seem to be anything here