2016-11-12 20 views
0

我正在寫下面的腳本來獲取GBP-EUR匯率,並使用matplotlib動態繪製它,因爲它代表腳本無限期地運行並更新圖形,但是標籤和軸限制不會出現,我將如何處理這個?如何設置matplotlib.animate的標籤和軸限制?

`#!/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

我想通了自己,刪除行ax1.clear()排序它。