![](/img/trans.png)
[英]I'm trying to know how I can use 'extent' in matplotlib to make my background image look decent
[英]How can I debug my background image in matplotlib?
我正在嘗試編寫一個對數學函數進行動畫處理的程序。 我想使用背景圖片。 我已經嘗試過了,該程序可以很好地啟動,但是很快它失去了對圖像的跟蹤,並弄亂了一切。 我該如何解決該問題?
我嘗試過實時調整圖像的大小以及x和y限制,但仍然會變得混亂。 我正在使用matplotlib和numpy。
該圖像在程序運行時:
但是,在此程序中有一個bug:
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style
import numpy as np
#[...]
def animate(data): #refresh data shown
x,y = data
xdata.append(x)
ydata.append(y)
xmin,xmax = ax.get_xlim()
if x >= xmax:
ax.set_xlim(xmin,2*xmax)
ax.figure.canvas.draw()
line.set_data(xdata,ydata)
return line
img = plt.imread("myimage.jpg")
ax.imshow(img, extent=[0, ax.get_xlim()[-1], ax.get_ylim()[0], ax.get_ylim()[-1]])
ani = animation.FuncAnimation(fig,animate,data_gen,blit=True,interval=10,repeat = False)
plt.show()
(我已嘗試將圖像上傳到此問題,但直到現在我仍然無法做到)
解決了! 由於某些原因,當我更改ylimit時它起作用。 也許圖像無法調整成不同的比例(?)。 修改內容:
if x >= xmax:
ax.set_xlim(xmin,2*xmax)
ax.set_ylim(-1.5*xmax,1.5*xmax)
ax.figure.canvas.draw()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.