PyVista: AttributeError: 'Plotter' object has no attribute 'ren_win'

PyVista: AttributeError: 'Plotter' object has no attribute 'ren_win'

我正在使用 PyVista 文档的示例代码:

import pyvista as pv
import matplotlib.pyplot as plt
from pyvista import examples

mesh = examples.load_random_hills()

p = pv.Plotter()
p.add_mesh(mesh, color=True)
p.show()

zval = p.get_image_depth()

plt.figure()
plt.imshow(zval)
plt.colorbar(label='Distance to Camera')
plt.title('Depth image')
plt.xlabel('X Pixel')
plt.ylabel('Y Pixel')
plt.show()

不幸的是,我收到以下错误:

File "C:\Users\user\Anaconda3\lib\site-packages\pyvista\plotting\plotting.py", line 3110, in get_image_depth
    ifilter.SetInput(self.ren_win)

AttributeError: 'Plotter' object has no attribute 'ren_win'

我不知道为什么会出现这个错误,我找不到任何关于这个问题的信息。

pv.Report的输出是:

  Date: Mon May 03 14:02:50 2021 Mitteleuropäische Sommerzeit



  Python 3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]

           pyvista : 0.29.1
               vtk : 9.0.1
             numpy : 1.16.5
           imageio : 2.6.0
           appdirs : 1.4.4
            scooby : 0.5.7
            meshio : 4.4.1
        matplotlib : 3.3.4
             PyQt5 : 5.9.2
           IPython : 7.8.0
             scipy : 1.3.1
              tqdm : 4.36.1

  Intel(R) Math Kernel Library Version 2019.0.4 Product Build 20190411 for
  Intel(R) 64 architecture applications

答案是必须存储图像。 所以我必须在 p.show()

之前插入 p.store_image = True