Rendering in 3D, resulting in very slow interactions

I am using the suggested solution here to render an image in 3D with matplotlib

. However, even with very reasonable image sizes ( 128x128

), the refresh rate is annoyingly slow. On my computer, the following cannot exceed 2fps.

import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
import numpy as np
X, Y = np.meshgrid(np.arange(128), np.arange(128))
Z = np.zeros_like(X)
im = np.sin(X/10 + Y/100)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=plt.cm.BrBG(im), shade=False)
plt.show()

      

Is there a way to speed up the above graph? I understand that mplot3d does not support hardware acceleration , but I feel that the simple graph above should be faster even on cpu.

+3


source to share


1 answer


You can try mayaVi library for better interactive data visualization.

#import matplotlib.pyplot as plt
#from mpl_toolkits import mplot3d
import numpy as np
from mayavi import mlab

X, Y = np.meshgrid(np.arange(128), np.arange(128))
Z = np.zeros_like(X)
im = np.sin(X/10 + Y/100)

#fig = plt.figure()
#x = fig.add_subplot(111, projection='3d')

src = mlab.pipeline.array2d_source(im)
warp = mlab.pipeline.warp_scalar(src)
normals = mlab.pipeline.poly_data_normals(warp)
surf = mlab.pipeline.surface(normals)
mlab.show()


#ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=plt.cm.BrBG(im), shade=False)

#plt.show()

      



MayaVi Documentation

+2


source







All Articles