(HOMEWORK) Help with Matplotlib

Question:
I think I have everything correct but it won’t print for some reason.
Code:

# Imports
import matplotlib.pyplot as plt
from gapminder import gapminder as gp

# Items for number 8
cun = list(gp['country'])
cont = list(gp['continent'])
yr = list(gp['year'])
gdp = list(gp['gdpPercap'])
pop = list(gp['pop'])
life = list(gp['lifeExp'])

'''
----- Number 8 -----
'''
pt_lif = []
pt_gdp = []
for i in range(0, len(cun)):
  if cun[i] == 'Portugal':
    pt_lif.append(life[i])
    pt_gdp.append(gdp[i])
plt.plot(pt_gdp,pt_lif, color = 'lightskyblue')
plt.title('Portugl Life Exp. to GDP')
plt.xlabel('GDP')
plt.ylabel('Life Exp.')
plt.show()

Note:
This is a homework assignment so please don’t give any straight-up answers but just help me and tell me where I might be going wrong.

I don’t think anything is wrong. It might be a case of case sensitive. For example, if your column is named “Continent” and here you used “continent” it won’t work.

Be sure that the gapminder library is installed too.

Im pretty sure your code isnt the problem.

I tried saving the plot in a file and it works fine. You can do it too:
Remove plt.show()
And in its place add plt.savefig("graph.svg")

A new file will be created which has your graph.

I have no idea why show() wouldnt work though…

I had code above it with input statements sorry y’all

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.