我正在编写以下脚本来获取GBP-EUR汇率并使用matplotlib动态绘制它,因为它代表脚本无限运行并更新图形,但标签和轴限制没有出现,我怎么会做这个?
`#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from yahoo_finance import Currency
from time import time
pound = Currency('GBPEUR')
prices = []
times = []
start = time()
n = 0
def animate(i):
pound.refresh()
prices.append(float(pound.get_bid()))
times.append((time() - start))
plt.axis([0,max(times),0,(max(prices)+5)])
plt.xlabel('Time since start, Seconds')
plt.ylabel('Pound-Euro conversion rate')
ax1.clear()
ax1.plot(times,prices)
while True:
pound.refresh()
prices.append(float(pound.get_bid()))
times.append((time() - start))
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
ani = animation.FuncAnimation(fig, animate, interval=1)
plt.show()`
答案 0 :(得分:0)
我自己想出了这一点,删除了排序ax1.clear()
的行。