Module 'matplotlib.pyplot' has no attribute 'ylim'

Hello, I am doing screen 11th of Pandas Visualizations and Grid Charts and I’m stuck because my plt is broken. I receive an error per subject.

From what I’ve found usually it’s caused by function reassigned as a variable, however I don’t see anything like that in the code.

My Code:

import pandas as pd
import matplotlib.pyplot as plt

traffic = pd.read_csv('traffic_sao_paulo.csv', sep=';')
traffic['Slowness in traffic (%)'] = traffic['Slowness in traffic (%)'].str.replace(',', '.')
traffic['Slowness in traffic (%)'] = traffic['Slowness in traffic (%)'].astype(float)

days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
traffic_per_day = {}
for i, day in zip(range(0, 135, 27), days):
    each_day_traffic = traffic[i:i+27]
    traffic_per_day[day] = each_day_traffic

for i, day in zip(range(1,6), days):
    plt.subplot(3, 2, i)
    plt.plot(traffic_per_day[day]['Hour (Coded)'],
        traffic_per_day[day]['Slowness in traffic (%)'])

Could anyone advise what’s the issue here?

AttributeError                            Traceback (most recent call last)
<ipython-input-1-bd53d58dfa9b> in <module>
     18         traffic_per_day[day]['Slowness in traffic (%)'])
     19     plt.title(day)
---> 20     plt.ylim([0,25])

AttributeError: module 'matplotlib.pyplot' has no attribute 'ylim'

Kind regards,

Hi, Bartlomiej
use tuple with two values - start and and, not list

bottom, top = ylim() # return the current ylim
ylim((bottom, top)) # set the ylim to bottom, top
ylim(bottom, top) # set the ylim to bottom, top

Hello Vadim,
Thank you - that worked!