[英]How to set labels and axes limits for matplotlib.animate?
我正在編寫以下腳本以獲取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()`
我自己弄清楚了這一點,刪除了對ax1.clear()
進行排序的行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.