'creating subplots for lag_plot [duplicate]
i want to plot 2 lag_plots by using matplotlib.pyplot.subplots. here is my code:
1.Grab Data
import pandas_datareader.data as web
import pandas as pd
import matplotlib.pyplot as plt
# start date
start = f"{date.today().year-3}-{date.today().month}-{date.today().day}"
# end date
end = date.today()
# 'MSFT' data
MSFT = pd.DataFrame(web.DataReader('MSFT' , start=start , end=end ,data_source='yahoo')['Close'])
# 'S&P 500' data
s_and_p500 = pd.DataFrame(web.DataReader('sp500' , start=start , end=end ,data_source='fred'))
2.Making Plots
fig , (ax1 , ax2) = plt.subplots(2,1)
fig.set_figheight(4)
fig.set_figwidth(20)
ax1 = pd.plotting.lag_plot(MSFT['Close'])
ax2 = pd.plotting.lag_plot(s_and_p500['sp500'])
as you can see, plt is plotting both in 1! I mean the area that I denoted in picture, is for this ax2 = pd.plotting.lag_plot(s_and_p500['sp500']) part of the code! but plt should put each of ax1 , ax2 in separated figures (first figure shouldn't be empty)!
How can I fix this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

