Which object contains the property ylim()
? In the code below (I have imported the required packages and x1
and y1
plot properly) to set the y-axis limits, I have to use plt.ylim()
, why is this so? In my own head, I would use ax1.ylim()
because the y-axis belongs to an ax object instance. Can someone please explain why this is not correct?
I saw this post here:
Why do many examples use "fig, ax = plt.subplots()" in Matplotlib/pyplot/python
which helped clarify it a little, but I'm still unsure. Thanks!
x1 = df_mstr1['datetime'].values
y1 = df_mstr1['tons'].values
fig1, ax1 = plt.subplots()
ax1.stackplot(x1, y1, color='blue')
plt.ylim(0,300)
fig1.savefig('page.pdf', format = 'pdf')