Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Introduction to Data Visualization with Matplotlib Getting Started with Data Visualization The Legend of Charting

Uncertain how to address "AttributeError: 'list' object has no attribute 'set_xlim'" - guidance welcome :)

Hello. Running through this course in Jupyter Notebooks with import matplotlib.pyplot as plt

I've tried several ways but keep getting similar attribute errors.

I have tried iterations of bottom, top = ylim(), ylim((bottom, top)), and ylim(bottom, top).

TIA. Code below.

plt.subplot(2, 1, 1)
panel_1 = plt.plot([1, 2, 3, 4], [1, 4, 9, 16], color='green', linestyle='dashdot', label='dashdot')
panel_1.set_xlim((0, 6))
panel_1.set_ylim((0, 20))

plt.subplot(2, 1, 2)
panel_2 = plt.plot([2, 3, 4, 5], [2, 3, 4, 5], color="#2B5B84", linestyle='dashed')
panel_2.set_xlim((0, 6))
panel_2.set_ylim((0, 20))

plt.show()

1 Answer

AAAAAAAANNND I found it.

I assigned the wrong section to my variable. In case anyone makes the same mistake, the issue was that my panel_1 and panel_2 variable should have been assigned the respective plt.subplot() methods, NOT the plt.plot() as I have above.

panel_1 = plt.subplot(2, 1, 1)
plt.plot([1, 2, 3, 4], [1, 4, 9, 16], color='green', linestyle='dashdot', label='dashdot')
panel_1.set_xlim([0, 6])
panel_1.set_ylim([0, 20])

panel_2 = plt.subplot(2, 1, 2)
plt.plot([2, 3, 4, 5], [2, 3, 4, 5], color="#2B5B84", linestyle='dashed')
panel_2.set_xlim([0, 6])
panel_2.set_ylim([0, 20])

plt.show()