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

2
  • 1
    This is not how FuncAnimation is supposed to work. You have to create a figure outside the Function that animates it by updating figure properties. See examples on SO or in the matplotlib gallery. For this, an object-oriented approach is preferable. Commented Mar 17, 2022 at 9: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" Commented Mar 17, 2022 at 12:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.