The following function plots stock price and volume when called. However, when it is called to create multiple plots iteratively only the last plot was shown up in output. How to flush the plot outputs to get the multiple plots. Trying the sleep function but it does not work.
import yfinance as yf
import matplotlib.pyplot as plt
import numpy as np
def skplot(ticker,dt1,dt2):
tck = yf.Ticker(ticker)
print(ticker+"\n"+"Market Cap:"+'${:,.0f}'.format(tck.info["marketCap"]))
df = yf.download(ticker, start=dt1, end=dt2)
top = plt.subplot2grid((4,4), (0, 0), rowspan=3, colspan=4)
top.plot(df.index, df["Close"])
plt.title(ticker)
bottom = plt.subplot2grid((4,4), (3,0), rowspan=1, colspan=4)
bottom.bar(df.index, df['Volume'])
plt.gcf().set_size_inches(10,8)
time.sleep(1)
#this one works
skplot("HLIT","2018-01-01","2019-07-11")
#called in a loop produce only the last chart
def stocklist():
'''Returns a list of stocks that met the criteria for rsi_plot'''
l=[
"HLIT" ,
"OHRP" ,
"HELE" ,
"CY" ]
for i in l:
# print(i)
skplot(i,"2018-01-01","2019-07-11")
return
stocklist()