Pyvista doesn't work in pycharm

Hi,

I am a new user of fenicsx. When I tried the tutorial on solving the Poisson equation, I ran into a problem with the visualization part.

Actually, I am running the program in Pycharm. When I run to use Pyvista to show the results, the program starts to run but cannot stop for a long time. In these lines

if not pyvista.OFF_SCREEN:
    plotter.show()
else:
    figure = plotter.screenshot("fundamentals_mesh.png")

However, it works if I didn’t use the unstructured grid, such as

import pyvista as pyvista
pyvista.set_jupyter_backend("pythreejs")

points = [[0, 0, 0],
          [1, 0, 0],
          [0.5, 0.667, 0]]
mesh = pyvista.PolyData(points)
mesh.plot(show_bounds=True, cpos='xy',color='red', point_size=20)

I’d like to know why it didn’t work and how can I do for that.

Thanks!

Are you running the notebook in pycharm, or a pythonscript in pycharm?

For your second example, you are using pythreejs, which is no longer part of pyvista’s backend.
Could you please specify what versions of pyvista you are using.

Thirdly, in the latter example, you have not added a “show” command, so it is unclear if you are using the same logic as in your first snippet.

Thanks for your kind reply!

At first, I run the code in the pythonscrpit in pycharm.

Secondly, I’m sorry that I forget to tell you I have removed the pythreejs in the brackets. The second example works. And my pyvista version is 0.43.1 which is the latest version.

Finally, I run plotter.show() but it still doesn’t stopped and nothing appear.

How did you install DOLFINx on your system, through apt, conda, docker or something else?

Are you also saying that something like the code in: Creating an Unstructured Grid — PyVista 0.43.1 documentation
does not run?

Could you also check the output of print(pyvista.OFF_SCREEN)?

I install by conda.

The code you posted can be ran.

And the output of print(pyvista.OFF_SCREEN) is false.

Thanks.

Try removing: pyvista.start_xvfb()
as that is the only difference in the codes.

It works!

Thank you very much!

Could you please tell me why this line pyvista.start_xvfb()affects the code running?

XVFB is a way to run off-screen plots, and is required for running inside docker images and in some other cases(like building the tutorial webpage).
See: Trame Jupyter Backend for PyVista — PyVista 0.44.dev0 documentation

Thanks for your answer! I’m trying to understand!