我正在繪制一些資料,但看不到。如果縮小,您會發現資料繪制在圖的另一側,并且視圖不會......自動更改以便能夠查看資料。有人可以幫我嗎?
from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
fig = plt.figure()
ax = fig.add_subplot()
line, = ax.plot([],[])
x = []
y = []
def animate(i):
x.append(i)
y.append((-1)**i)
line.set_data(x, y)
return line,
anim = FuncAnimation(fig, animate, frames=200, interval=100, blit=True)
plt.show()
uj5u.com熱心網友回復:
根據https://stackoverflow.com/a/7198623/1008142,您需要呼叫軸relim和autoscale_view方法。
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
fig = plt.figure()
ax = fig.add_subplot()
line, = ax.plot([],[])
x = []
y = []
def animate(i):
x.append(i)
y.append((-1)**i)
line.set_data(x, y)
ax.relim()
ax.autoscale_view()
return line,
anim = FuncAnimation(fig, animate,
frames=200, interval=100, blit=True)
plt.show()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/447251.html
標籤:python-3.x matplotlib matplotlib-动画
