Pycharm vs Canopy and matplotlib

17 Views Asked by At

I'm working on the baby names lab that grabs the US census data of baby names from 1880 to 2021 and plots the occurrence of two chosen names on a graph.

Canopy IDE does a great job with the lab:

Canopy Graph

yet PyCharm does not do a great job:

PyCharm Graph

One thing: The matplotlib in Canopy comes with Canopy and it's older than the current matplotlib I'm using in PyCharm. Not sure if that's a big deal.

Can you look at the code and give me a reason why PyCharm is not giving a good graph and what changes I need to make to get a good graph in PyCharm?

import os.path
import matplotlib.pyplot as plt
from matplotlib.pyplot import plot, show

name1='Michael'
name2='Michele'

# Get the directory name for data files
directory = os.path.dirname(os.path.abspath(__file__))  

#initialize the aggregators
years1=[]
number_of_people1=[]
years2=[]
number_of_people2=[]

# Scan one year's file at a time
for year in range(1880,2021):
    # Open the file
    filename = os.path.join(directory, 'yob'+str(year)+'.txt')
    datafile = open(filename,'r')
    # Go through all the names that year
    for line in datafile:
        name, gender, number = line.split(',')
        # Aggregate based on name1
        if name == name1 and gender == 'M':
            years1 += [year]
            number_of_people1 += [number]    
        #Aggregate based on name2
        if name == name2 and gender == 'F':
            years2 += [year]
            number_of_people2 += [number]        
    #Close that year's file
    datafile.close()
    
# Plot on one set of axes.
fig, ax = plt.subplots(1,1)
ax.plot(years1,number_of_people1,'#0000FF')
ax.plot(years2,number_of_people2,'#FF00FF')

ax.set_title('U.S. Babies Named Michael(blue) or Michele(pink)')
fig.show()

I've tried both IDEs with the listed code and got good results from Canopy but bad results from PyCharm.

0

There are 0 best solutions below