Tôi đang âm mưu dữ liệu địa lý và do đó cần bản đồ cơ sở. Dựa trên câu trả lời của captain_M và một báo cáo thảo luận/lỗi trên https://github.com/matplotlib/matplotlib/issues/6139 tôi gửi một phản ứng lấy cảm hứng từ tacaswell cho phép bạn sử dụng contourf trong một phim hoạt hình của 2 dữ liệu chiều và lưu nó như mp4 nếu bạn có ffmpeg:
from matplotlib import animation
from matplotlib import pyplot as plt
import numpy as np
from mpl_toolkits.basemap import Basemap
fig, ax = plt.subplots()
# set up map projection
m = Basemap(projection='nsper',lon_0=-0,lat_0=90)
m.drawcoastlines()
m.drawparallels(np.arange(0.,180.,30.))
m.drawmeridians(np.arange(0.,360.,60.))
# some 2D geo arrays to plot (time,lat,lon)
data = np.random.random_sample((20,90,360))
lat = np.arange(len(data[0,:,0]))
lon = np.arange(len(data[0,0,:]))
lons,lats = np.meshgrid(lon,lat)
# ims is a list of lists, each row is a list of artists to draw in the
# current frame; here we are animating three artists, the contour and 2
# annotatons (title), in each frame
ims = []
for i in range(len(data[:,0,0])):
im = m.contourf(lons,lats,data[i,:,:],latlon=True)
add_arts = im.collections
text = 'title={0!r}'.format(i)
te = ax.text(90, 90, text)
an = ax.annotate(text, xy=(0.45, 1.05), xycoords='axes fraction')
ims.append(add_arts + [te,an])
ani = animation.ArtistAnimation(fig, ims)
## If you have ffmpeg you can save the animation by uncommenting
## the following 2 lines
# FFwriter = animation.FFMpegWriter()
# ani.save('basic_animation.mp4', writer = FFwriter)
plt.show()
thể trùng lặp của [Sử dụng matplotlib.animate animate một âm mưu đường viền trong python] (http://stackoverflow.com/questions/16915966/using-matplotlib-animate-to-animate-a-contour-plot -in-python) – Dan
Những gì tôi đã làm là tạo ra một ô đường bao mới mỗi lần, và để ẩn cái cũ tôi làm 'cont.set_alpha (0)'. Hacky. Phải có một phương thức 'set_data'. –