Reputation: 43
This is probably a simple question, but setting the bottom y=axis simply isn't working. I believe it is occurring as a result of me using the area chart, but I'm not sure how to resolve it. Here is my current code.
fig, (ax1, ax2) = plt.subplots(2, sharex=True, sharey=True)
fig.suptitle('SPY Chart')
ax1.set_ylim(bottom=150, top=450)
spyData['Close'].plot(kind='area',ax=ax1)
spyData['Close'].plot(ax=ax2)
Changing the value of the top works perfectly well, but the bottom won't.
Upvotes: 4
Views: 534
Reputation: 80544
The plot commands called after setting the ylim
s changes these limits again. Calling set_ylim()
after the plot commands solves this:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
spyData = pd.DataFrame({'Close': np.random.normal(0.1, 10, 200).cumsum() + 200})
spyData.set_index(pd.date_range('20200101', periods=len(spyData)), inplace=True)
fig, (ax1, ax2) = plt.subplots(2, sharex=True, sharey=True)
spyData['Close'].plot(kind='area', ax=ax1)
spyData['Close'].plot(ax=ax2)
ax1.set_ylim(bottom=150, top=450)
ax1.margins(x=0) # suppress white space left and right
plt.show()
Upvotes: 1