# Plot data from a .pvd file in PythonView

**URL:** https://discourse.paraview.org/t/plot-data-from-a-pvd-file-in-pythonview/14243
**Category:** ParaView Support
**Created:** [March 23, 2024, 8:13pm UTC](https://discourse.paraview.org/t/plot-data-from-a-pvd-file-in-pythonview/14243 "2024-03-23T20:13:44Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![legno](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/l/e9bcb4/32.png) [@legno](https://discourse.paraview.org/u/legno)
#### Post date: [March 23, 2024, 8:13pm UTC](https://discourse.paraview.org/t/plot-data-from-a-pvd-file-in-pythonview/14243/1 "2024-03-23T20:13:44Z")

</div>

Hello, following [this tutorial](https://www.youtube.com/watch?v=OeG0XPv3eZw&ab_channel=TuxRiders) I managed to create a histogram of the datapoints from a Paraview file with PythonView. Now I would like to consider the Paraview file attached, and plot it in PythonView. Note that the .pvd file attached represents a function of two variables, say, f(x,y).

Now I execute the following script with PythonView

```auto
from paraview import python_view
import numpy as np
import matplotlib.pyplot as plt

def render(view, width, height):
    figure = python_view.matplotlib_figure(width, height)
    ax = figure.add_subplot(1,1,1)

    ax.set_title('My beautiful plot')
    ax.set_xlabel('x axis')
    ax.set_ylabel('y axis')

    data_object = view.GetVisibleDataObjectForRendering(0)
    x = data_object.GetPointData().GetArray('f_24')
    from paraview.numpy_support import vtk_to_numpy
    np = vtk_to_numpy(x)

    
    return python_view.figure_to_image(figure)

```

where I would like to store in np the values of f(x,y). However, when I run this Python code in paraview I get the error message

```auto
Traceback (most recent call last):
  File "/Applications/ParaView-5.12.0.app/Contents/Python/paraview/python_view.py", line 156, in call_render
    image = render_function(view, width, height)
  File "Script", line 16, in render
  File "/Applications/ParaView-5.12.0.app/Contents/Python/vtkmodules/util/numpy_support.py", line 215, in vtk_to_numpy
    typ = vtk_array.GetDataType()
AttributeError: 'NoneType' object has no attribute 'GetDataType'

```

What am I doing wrong? I would like to get the values of f(x,y) stored into an array, and similarly for the values of x, which I would like to store in a second array, and for the values of y, which I would like to store in a third array.

Thank you

[solution.pvd](https://discourse.paraview.org/uploads/short-url/RW4mKQHgcmxJUBWl95YEDOAMoI.pvd) (170 Bytes)  
[solution000000.vtu](https://discourse.paraview.org/uploads/short-url/qGQSHT510FjjDGqxnFIrC1Xmuhx.vtu) (671.3 KB)

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [July 4, 2024, 9:17pm UTC](https://discourse.paraview.org/t/plot-data-from-a-pvd-file-in-pythonview/14243/2 "2024-07-04T21:17:44Z")

</div>

Hi @legno,

You’ll need to define a `setup_data(view)` function to enable transfer of the arrays from the server to the view:

```python
def setup_data(view):
    view.EnableAllAttributeArrays()

```

Add that to your script and it should work fine.

By the way, that’s covered in the tutorial you shared at [https://youtu.be/OeG0XPv3eZw?t=814](https://youtu.be/OeG0XPv3eZw?t=814)
