0

I have the following code which pulls stock data using yfinance. The output plot needs to be from the end of one trading session to the start of the next trading session, 4pm to 9:30am should be removed in the plot. How do I do this efficiently?

data = yf.download(tickers="MSFT", period="5d", interval="1m")
plt.figure(figsize=(12,8))
data['Open'].plot()

enter image description here

Jake
  • 49
  • 4
  • Is this a pandas question? If so, use `groupby()` and plot each group separately. Still, you should provide an [MCVE](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – Mr. T Nov 20 '20 at 17:39
  • I need them all to be contained on the same plot. I need a continuous time series plot of stock data that essentially skips over times when the market is closed. Just replicating how normal stock plots look right now. But not sure how to do this. – Jake Nov 20 '20 at 18:44
  • 1
    As I said. `groupby` day and plot all groupby objects individually in the same `ax` object. And without an MCVE, not many people will put effort into this - datetime objects can be particularly complicated when it comes to interaction between pandas and matplotlib. – Mr. T Nov 20 '20 at 19:11

0 Answers0