Matplotlib 3DPlot Líneas adicionales cuando las dimensiones no son iguales
Considere este MWE:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
from matplotlib import cm
n = 15
m = 12
x = np.linspace(-5, 5, n)
y = np.linspace(-5, 5, m)
Z = np.zeros((m, n))
for i in xrange(m):
for j in xrange(n):
Z[i, j] = x[j]**2 + y[i]**2
### Plot surface ###
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X, Y = np.meshgrid(x, y)
ax.plot_surface(X, Y, Z)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('Z')
plt.show()
Tenga en cuenta en particular que las dimensionesn
ym
no son iguales La trama resultante tiene algunas líneas extrañas colgando, así como también un extraño color:
¿Qué está pasando aquí y cómo puedo evitar esto?