0

Appreciating your time and effort to go through my code and helping me to find the solution. I am using FuncAnimation of Matplotlib to refresh/update my plot every 1min.

The Data is extracted using Yahoo finance every 1min. But I am getting following error:

in _draw_frame self._drawn_artists = self._func(framedata, *self._args) TypeError: 'NoneType' object is not callable

Below is my code:

import yfinance as yf

import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

def Get_Data():
    
    Data = yf.download(tickers="VIPIND.NS",interval="1m", period="1d")
    Data.reset_index(inplace = True)
    Data['Datetime'] = Data['Datetime'].dt.tz_convert('Asia/Kolkata').dt.tz_localize(None)
    Data['Datetime'] = pd.to_datetime(Data['Datetime'])
    Data=Data.set_index('Datetime')
    print("Refreshed")
    
    plt.figure(1)
    plt.cla()
    plt.xticks()
    plt.plot(Data['Close'], linewidth = 2)#,label = f'Close at {Data.index[-1]}')
    plt.title(f'Close Price at {Data.index[-1]}')
    plt.xlabel("Time")
    plt.show()

    
    return

LivePlot = FuncAnimation(plt.gcf(),Get_Data(),interval=60000)

Please guide me on where am I going wrong ? and how to resolve this issue.

Regards Sudhir

kbsudhir
  • 415
  • 1
  • 6
  • 15
  • 1
    This is not how FuncAnimation is supposed to work. You have to create a figure outside the `Func`tion that animates it by updating figure properties. See examples on SO or in the [matplotlib gallery](https://matplotlib.org/stable/gallery/index.html#animation). For this, an [object-oriented approach](https://matplotlib.org/matplotblog/posts/pyplot-vs-object-oriented-interface/) is preferable. – Mr. T Mar 17 '22 at 09:33
  • Thanks Mr. T. I followed your guidance and made necessary changes to the code. I have brought the plotting code out of the function. Now I am getting the following error: "self._drawn_artists = self._func(framedata, *self._args) TypeError: 'DataFrame' object is not callable" – kbsudhir Mar 17 '22 at 12:53

0 Answers0