i have a problem plotting polygons using matplotlib in 3D. Under some circumstances there always seems to occur some kind of graphical error where polygons are shown that are covered by other polygons. This results in some really weird locking plots. But i can't figure out, where i make an error in the code. Maybe yome of you have had the problem befor and already a solution for it. My example code is as follows:
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.pyplot as plt
import numpy as np
z = np.zeros((10,10))
z[5,5] = 5
z[4,5] = 2
z[4,4] = 2.8
nx,ny = (10,10)
xv = np.linspace(0,9,nx)
yv = np.linspace(0,9,ny)
x,y = np.meshgrid(xv,yv)
y = np.flipud(y)
fig = plt.figure()
ax = Axes3D(fig)
ax.set_xlim3d(np.min(np.array(x)),np.max(np.array(x)))
ax.set_ylim3d(np.min(np.array(y)),np.max(np.array(y)))
ax.set_zlim3d(np.min(np.array(z)),np.max(np.array(z)))
ax.view_init(elev=45,azim=0)
ax.xaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))
ax.yaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))
ax.zaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))
ax.xaxis._axinfo["grid"]['color'] = (1,1,1,0)
ax.yaxis._axinfo["grid"]['color'] = (1,1,1,0)
ax.zaxis._axinfo["grid"]['color'] = (1,1,1,0)
ax.set_axis_off()
for d1 in range(ny-1):
for d2 in range(nx-1):
xp = [x[d1,d2],x[d1+1,d2],x[d1,d2+1]]
yp = [y[d1,d2],y[d1+1,d2],y[d1,d2+1]]
zp = [z[d1,d2],z[d1+1,d2],z[d1,d2+1]]
verts = [list(zip(xp,yp,zp))]
ax.add_collection3d(Poly3DCollection(verts,facecolor='mediumblue',
linewidths=1,edgecolor='black'))
xp = [x[d1+1,d2],x[d1+1,d2+1],x[d1,d2+1]]
yp = [y[d1+1,d2],y[d1+1,d2+1],y[d1,d2+1]]
zp = [z[d1+1,d2],z[d1+1,d2+1],z[d1,d2+1]]
verts = [list(zip(xp,yp,zp))]
tri = ax.add_collection3d(Poly3DCollection(verts,facecolor='goldenrod',
linewidths=1,edgecolor='black'))
plt.savefig('out.png')
A figure that shows the problem can be seen here, have a look at the 6th column from the left, close to the middle of the plot. These error seems to be realted to the angle, in ohter azimut angles this error does not occur. But it is not a solution to change the azimuth angle because the such errors can occur in other position. Does someone know what i have done wrong and how to do it right?

