2015-08-13 99 views
0

我一直在嘗試對錶面進行動畫處理。到目前爲止,所有的動畫作品,以及曲面都很好地繪製。然而,我的表面上有一些直線,看起來像是來自軸線。有沒有辦法擺脫這個?Python:繪製在動畫中的plot_surface()上的網格線

# Plot first figure 
fig = plt.figure() 
ax = fig.gca(projection='3d') 
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm, 
    vmin = 900, vmax = 1430, linewidth=0, antialiased=False) 
fig.colorbar(surf, shrink=0.5, aspect=5) 

def data(i, X,Y,Z, surf): 
    #change soln variable for the next frame 
    ax.clear() 
    (a,b) = val[i].shape 
    X = np.arange(0, b) 
    Y = np.arange(0, a) 
    X,Y = np.meshgrid(X, Y) 
    Z = val[i] 
    surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm, 
     vmin = 900, vmax = 1430, linewidth=0, antialiased=False) 
    ax.set_xlim(0, 60) 
    ax.set_ylim(0, 280) 
    ax.set_zlim(900, 1430) 
    ax.view_init(azim=10, elev=20) 
    ax.zaxis.set_major_locator(LinearLocator(10)) 
    ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f')) 

return surf 

# Add animation 
ani = animation.FuncAnimation(fig, data, fargs=(X, Y, Z, surf), 
    frames=val.size, interval=0.05 , blit=False, repeat=False) 

# Full screen window 
figManager = plt.get_current_fig_manager() 
figManager.window.showMaximized() 

plt.show() 

enter image description here

回答

0

這是一個錯誤(在這裏看到:https://github.com/matplotlib/matplotlib/issues/750/)。解決方法是通過刪除所有對象手動清除軸。

你需要導入包含表面,所以你可以參考它的類:from mpl_toolkits.mplot3d.art3d import Poly3DCollection

然後,

artists = ax.findobj(match = Poly3DCollection) 
for obj in artists: 
    obj.remove() 
+0

謝謝更換ax.clear()!它完美的工作! :d –