Plotting data computed in python shell

Please help how to access data created in a Python Shell from a Pipeline Browser. I need to plot the data that I calculated using python shell. So that each cell corresponds to a python list item

You need to use a TrivialProducer.

See an example here :
https://cmake.org/pipermail/paraview/2011-February/020120.html

Or here :
https://gitlab.kitware.com/paraview/paraviewjupyterkernel/-/blob/main/PVKernelPlugin/PVInterface.py#L9

1 Like

Thanks for the help. But we still can’t figure it out. I have a python list user_data, each cell has a corresponding value in this list. Next I write

t = TrivialProducer() #TrivialProducer1 is created in the Pipeline Browser
filter = t.GetClientSideObject()
filter.SetOutput(user_data)

And I get the TypeError: SetOutput argument %Id: %V

what is user_data ? How is it created ?

This is a python list created by a script in a python shell. For example:

user_data=[0.1, 0.2, 0.3, 0.4, 0.5]

It is not clear how exactly this data should be presented. Obviously, this data can be presented in any form as a list or a tuple, and combined with any IDs. For example:

user_data=[ [1,0.1], [2,0.2], [3,0.3], [4,0.4], [5,0.5] ]

You need to transform to a vtkTable.

See here : https://stackoverflow.com/questions/47530972/numpy-array-to-vtk-table

1 Like

Thank you very much for your help! The transfer of data from Python Shell to the Pipeline Browser could be done using the following script

import numpy as np
import vtk

# Initial user data as a standard Python list
user_data = [0.1, 0.2, 0.3, 0.4, 0.5]

# Converting Python list to NumPy array
# N.B. In general,  this is a good idea for Python scripting to perform calculations using the NumPy library
arr = np.array(user_data)

# Converting NumPy array to VTK array
vtkarr = vtk.vtkDoubleArray() 
vtkarr.SetNumberOfComponents(1) 
vtkarr.SetNumberOfTuples(arr.shape[0])
# alternatively SetNumberOfTuples(arr.shape[0]) for a two-dimensional array (more than one data column)
vtkarr.SetVoidArray(arr,arr.size,0)
vtkarr.SetName("User Data")

# Creating of the VTK table
tab=vtk.vtkTable()
tab.GetRowData().AddArray(vtkarr)

# Creating of the TrivialProducer object accessible from the Pipeline Browser 
t=TrivialProducer()
t.GetClientSideObject().SetOutput(tab)

Hello,
I have a similar problem. Do you know how to plot over time data computed via python shell?