Proposition of Python View parameters

Hi community,

The Python View is a 2D Render View that is configured from a python script, given as property.
One use case is to use external tools like Matplotlib to do the rendering, like here:


User script

ParaView expects 2 methods to be defined in the script in order to works

def setup_data(view):

def render(view, width, height):
  return someVTKImageData

This is not easy to discover, and easy to break.


There is no way to manipulate parameters from a GUI. All of them should be defined and modified directly in the python script. This is not a user friendly way to control a view in the application.

Possible improvements

This View make me think about Programmable Filter and I wonder if we may modify the Python View to be more consistent with it.

I mean:

  1. Add an API on vtkPythonView to add a list of custom parameters (AddParameter(string, string)) and the relevant property
  2. Create a dedicated property for each method content
  3. Move setup_data to the Python Representation part

Those points can be done incrementally.
With the first, it makes it possible to create a XML plugin to create a python view with a hardcoded script while having accessible properties.

Having one property per method seems the correct way to do to me. Expecting only the function content (without def line) brings consistency with ProgrammableXXX filters, and make it easier for vtkPythonView to hook it up. An alternative is to let the def function(): line be part of the property but put it as the default value so it is more discoverable.

The last point is for consistency with ParaView paradigm. This implies the previous point.

Any thought?

Workaround to control the python with a GUI: Customize Python View with Python plugins

@cory.quammen @Charles_Gueunet FYI

Looks nice to me. What about PythonPlugins ? Would that make the python view compatible with python plugins ?

Nope. Python plugins are still another thing, I didn’t investigate for now.

Currently, the python plugins are vtkAlgorithm subclasses with inline XML. We should extend support for vtkView or such.

1 Like

The Python View definitely has room for improvement, and these proposals make sense. The only thing I’m not sure about is moving the setup_data to the representation properties. This will move where you set the script in the Properties panel, which may make it harder to find in the UI. You could probably list it last in the representation so that it appears close to the View section in the Properties panel.


As a long-time user of python matplotlib, I find this quite nice!

Is the goal to expose:

  1. only the matplotlib render window (so all the configuration stays inside the python script)
  2. the matplotlib parameters so no python script is used

If 1. developping/debugging the script (inside the property panel) will be hard and a solution as an external python plugin seems better
If 2. this seems like a trendemous amount of work, and would be redundant with the existing “raw” plots from paraview (4. Displaying data — ParaView Documentation 5.11.0 documentation)

@ltetrel not sure what you mean.

The PythonView script should return a vtkImageData that is displayed directly in the view (and its not gonna change). We provide some python utility functions for data conversion, so it easier to use other tools like matplotlib inside the script to generate the final image.

What I suggest is to let the user initialize some python variable from the GUI. It is up to the dev to choose which variable to expose and to synchronize the name in the GUI and the name in the python script.