Python matplotlib打印曲面太慢
我有一个60行2000列的矩阵S。我需要这个矩阵的3d图。 这就是我所做的:Python matplotlib打印曲面太慢,python,matplotlib,plot,Python,Matplotlib,Plot,我有一个60行2000列的矩阵S。我需要这个矩阵的3d图。 这就是我所做的: S.dtype = 'float64' S = sk.preprocessing.scale(S) n, p = S.shape X = np.arange(0, n) Y = np.arange(0, p) X, Y = np.meshgrid(X, Y) def funz(x,y): return S[x, y] Z = funz(X, Y) fig = plt.figure() ax = fig.
S.dtype = 'float64'
S = sk.preprocessing.scale(S)
n, p = S.shape
X = np.arange(0, n)
Y = np.arange(0, p)
X, Y = np.meshgrid(X, Y)
def funz(x,y):
return S[x, y]
Z = funz(X, Y)
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1,
cmap=cm.RdBu,linewidth=0, antialiased=False)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
这是可行的,但情节过于沉重,因为不可能为了更好地形象化而移动它。我怎样才能解决这个问题
特别是我需要找到3d绘图的良好视图以将其保存为pdf图形。
matplotlib
没有“真实”3d绘图。通常,对于复杂或大型曲面,您会使用类似于mayavi
的内容,而不是matplotlib
举个简单的例子:
import numpy as np
from mayavi import mlab
x, y = np.linspace(-15, 15, 200), np.linspace(-15, 15, 200)
xx, yy = np.meshgrid(x, y)
z = np.cos(np.hypot(xx, yy)) + np.sin(np.hypot(xx + 5, yy + 5))
mlab.figure(bgcolor=(1,1,1))
# We'll use "surf" to display a 2D grid...
# warp_scale='auto' guesses a vertical exaggeration for better display.
# Feel free to remove the "warp_scale" argument for "true" display.
mlab.surf(x, y, z, warp_scale='auto')
mlab.show()
为什么需要3D绘图?二维
轮廓图
或轮廓图
不是更好地理解数据吗?我无法描绘任何3D绘图更好的情况/数据。我需要3D绘图。目前,我得到了一个体面的(不是最佳的)结果与matlab冲浪功能。我对matplotlib不能得到同样的结果感到惊讶。