我想画外汇实时走势图,如下是我的程序:
import matplotlib.pyplot as plt
import requests
import json
import traceback
plt.close() #clf() # 清图 cla() # 清坐标轴 close() # 关窗口
fig=plt.figure()
ax=fig.add_subplot(1,1,1)
ax.axis("equal") #设置图像显示的时候XY轴比例
plt.grid(True) #添加网格
plt.ion() #互动模式开始
url = "https://api-fxpractice.oanda.com/v1/prices"
instruments = 'EUR_USD,USD_CAD'
account_id = 'cawa11'
params = {'instruments':instruments,'accountId':account_id}
access_token = 'a554db3a48ac8180a6996a5547ba1663-ac5947e64456cc5842a34f4ce05e4380'
headers = {'Connection': 'Keep-Alive',
'Accept-Encoding': 'gzip,deflate',
'Authorization':'Bearer '+access_token}
time = 0
try:
while True:
r = requests.get(url,headers = headers, params=params)
price = r.json()
obsX = time #price['prices'][0]['time']
time = time + 1
obsY = round((price['prices'][0]['ask']+price['prices'][0]['bid'])/2,5) #EUR/USD中间价
ax.scatter(obsX,obsY,c='b',marker='.') #散点图
plt.pause(0.0001)
except:
print(traceback.format_exc())
pass
我遇到的问题是:
1.报错:
Warning (from warnings module):
File "C:Python34libsite-packagesmatplotlibbackend_bases.py", line 2445
warnings.warn(str, mplDeprecation)
MatplotlibDeprecationWarning: Using default event loop until function specific to this GUI is implemented
2.显示不出应有的效果,我希望一开始的0点不在中间而在最左边,可能是ax.axis("equal")
的问题
请大家帮助,谢谢