# Plotting data computed in python shell

**URL:** https://discourse.paraview.org/t/plotting-data-computed-in-python-shell/4771
**Category:** ParaView Support
**Tags:** python
**Created:** [July 7, 2020, 4:30pm UTC](https://discourse.paraview.org/t/plotting-data-computed-in-python-shell/4771 "2020-07-07T16:30:50Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Andrei](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/9fc29f/32.png) [@Andrei](https://discourse.paraview.org/u/Andrei)
#### Post date: [July 7, 2020, 4:30pm UTC](https://discourse.paraview.org/t/plotting-data-computed-in-python-shell/4771/1 "2020-07-07T16:30:50Z")

</div>

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

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [July 8, 2020, 7:36am UTC](https://discourse.paraview.org/t/plotting-data-computed-in-python-shell/4771/2 "2020-07-08T07:36:30Z")

</div>

You need to use a TrivialProducer.

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

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

---

<div class="post-metadata">

### Author: ![Andrei](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/9fc29f/32.png) [@Andrei](https://discourse.paraview.org/u/Andrei)
#### Post date: [July 23, 2020, 12:59pm UTC](https://discourse.paraview.org/t/plotting-data-computed-in-python-shell/4771/3 "2020-07-23T12:59:54Z")

</div>

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

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [July 23, 2020, 1:13pm UTC](https://discourse.paraview.org/t/plotting-data-computed-in-python-shell/4771/4 "2020-07-23T13:13:32Z")

</div>

what is user\_data ? How is it created ?

---

<div class="post-metadata">

### Author: ![Andrei](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/9fc29f/32.png) [@Andrei](https://discourse.paraview.org/u/Andrei)
#### Post date: [July 23, 2020, 1:32pm UTC](https://discourse.paraview.org/t/plotting-data-computed-in-python-shell/4771/5 "2020-07-23T13:32:50Z")

</div>

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] ]

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [July 23, 2020, 1:36pm UTC](https://discourse.paraview.org/t/plotting-data-computed-in-python-shell/4771/6 "2020-07-23T13:36:54Z")

</div>

You need to transform to a vtkTable.

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

---

<div class="post-metadata">

### Author: ![Andrei](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/9fc29f/32.png) [@Andrei](https://discourse.paraview.org/u/Andrei)
#### Post date: [July 28, 2020, 11:47am UTC](https://discourse.paraview.org/t/plotting-data-computed-in-python-shell/4771/7 "2020-07-28T11:47:03Z")

</div>

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)
```

---

<div class="post-metadata">

### Author: ![abon](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@abon](https://discourse.paraview.org/u/abon)
#### Post date: [March 3, 2023, 8:27am UTC](https://discourse.paraview.org/t/plotting-data-computed-in-python-shell/4771/8 "2023-03-03T08:27:31Z")

</div>

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