# How to set render function for each PythonView?

**URL:** https://discourse.paraview.org/t/how-to-set-render-function-for-each-pythonview/9137
**Category:** ParaView Support
**Tags:** python
**Created:** [March 7, 2022, 2:25pm UTC](https://discourse.paraview.org/t/how-to-set-render-function-for-each-pythonview/9137 "2022-03-07T14:25:00Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![pindakaas](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/cab0a1/32.png) [@pindakaas](https://discourse.paraview.org/u/pindakaas)
#### Post date: [March 7, 2022, 2:25pm UTC](https://discourse.paraview.org/t/how-to-set-render-function-for-each-pythonview/9137/1 "2022-03-07T14:25:00Z")

</div>

Hi,

I have two different PythonView’s, each with its own script. Each script contains a render function. I’d expect that each render function would update the view in which it is defined, but it seems that all views share the same render function definition.

For example, PythonView1’s script calls to render plot X. Afterwards, a different PythonView2’s script calls to render plot Y. The result is that both views contain plot Y. If PythonView2 doesn’t call to render anything, it will contain plot X. Why is that?

Kind regards,  
Davis

---

<div class="post-metadata">

### Author: ![pindakaas](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/cab0a1/32.png) [@pindakaas](https://discourse.paraview.org/u/pindakaas)
#### Post date: [March 8, 2022, 8:07am UTC](https://discourse.paraview.org/t/how-to-set-render-function-for-each-pythonview/9137/2 "2022-03-08T08:07:13Z")

</div>

Tried using the python\_view.call\_render function, which seems to be used exactly in cases like this, but a simple example (see below) fails. Nothing shows up and after a few clicks Paraview crashes.

```auto
import numpy as np
from paraview.simple import *
from paraview import python_view

def render2(view, width, height):
    print(view)
    figure = python_view.matplotlib_figure(width, height)
    ax = figure.add_subplot(1, 1, 1)
    x = np.linspace(1, 2*np.pi, 100)
    y = np.sin(x)
    ax.plot(x, y)
    figure.tight_layout()
    ax.grid()
    return python_view.figure_to_image(figure)
    # Width - 2081, height - 912

python_view.call_render(render2, view, width, height)

Edit: Fixed code formatting
```
