'Matplot figure not rendered getting "Not Responding" message
I am trying to update candlestick chart every 1min. I am using mplfinance to create candlestick plots and yahoo finance to get the data.
I am using time.sleep to pause and refresh.
Issue is plot window shows "Not Responding". Screenshot attached below. Where am I going wrong ? Requesting guidance.
Below is the complete code.
#Importing packages
import yfinance as yf
# Calling Pandas to create dataframe
import pandas as pd
#Importing Datetime package
from datetime import datetime, timedelta
from dateutil.parser import parse
import pytz
import matplotlib.pyplot as plt
import mplfinance as mpf
import time
import warnings
warnings.filterwarnings("ignore")
LiveData = yf.download(tickers="LCID",interval="1m", period="1d")
LiveData.reset_index(inplace = True)
LiveData['Datetime'] = LiveData['Datetime'].dt.tz_convert('US/Eastern').dt.tz_localize(None)
LiveData['Datetime'] = pd.to_datetime(LiveData['Datetime'])
LiveData=LiveData.set_index('Datetime')
fig = mpf.figure(style='charles',figsize=(12,7))
ax1 = fig.add_subplot()
ax1.xaxis.set_major_locator(plt.MultipleLocator(1))
ax1.xaxis.set_major_locator(plt.MaxNLocator(20))
mpf.plot(LiveData,ax=ax1, type='candle',show_nontrading=True,volume=False)
mpf.plot(LiveData,ax=ax1, type='line',show_nontrading=True,volume=False)
def Get_Data(LiveData):
time.sleep(60)
Data = yf.download(tickers="LCID",interval="1m", period="1d")
if len(Data)<=len(LiveData):
return print('No Update')
Data.reset_index(inplace = True)
Data['Datetime'] = Data['Datetime'].dt.tz_convert('US/Eastern').dt.tz_localize(None)
Data['Datetime'] = pd.to_datetime(Data['Datetime'])
Data=Data.set_index('Datetime')
#fig = mpf.figure(style='charles',figsize=(12,7))
#ax1 = fig.add_subplot()
ax1.clear()
ax1.xaxis.set_major_locator(plt.MultipleLocator(1))
ax1.xaxis.set_major_locator(plt.MaxNLocator(20))
mpf.plot(Data,ax=ax1, type='candle',show_nontrading=True,volume=False)
mpf.plot(Data,ax=ax1, type='line',show_nontrading=True,volume=False)
return
def get_time():
now = datetime.now()
nyc_time = datetime.now(tz=pytz.timezone('US/Eastern'))
nyc_time = nyc_time.strftime("%H:%M:%S")
alarm = now.replace(hour=16, minute=0, second=0, microsecond=0)
opentime = now.replace(hour=9, minute=30, second=0, microsecond=0)
alarm = alarm.strftime("%H:%M:%S")
opentime = opentime.strftime("%H:%M:%S")
nyc_time = parse(nyc_time)
alarm = parse(alarm)
opentime = parse(opentime)
return nyc_time, alarm, opentime
while True:
nyc_time, alarm, opentime = get_time()
if nyc_time > alarm or nyc_time < opentime:
if nyc_time > alarm:
print("NASDAQ Closed for the day")
break
if nyc_time < alarm:
print("NASDAQ has not opened for the day")
break
Get_Data(LiveData)
Appreciating your time and guidance
Sudhir
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

