# Plot Nodes in Slicer

**URL:** <https://discourse.slicer.org/t/plot-nodes-in-slicer/8553>\
**Category:** Development\
**Created:** [September 24, 2019, 9:06pm UTC](https://discourse.slicer.org/t/plot-nodes-in-slicer/8553 "2019-09-24T21:06:28Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![wieke.prummel](https://avatars.discourse-cdn.com/v4/letter/w/58956e/32.png) [@wieke.prummel](https://discourse.slicer.org/u/wieke.prummel)\
**Post date:** [September 24, 2019, 9:06pm UTC](https://discourse.slicer.org/t/plot-nodes-in-slicer/8553/1 "2019-09-24T21:06:28Z")

</div>

Hi everyone,

I am working on a module to generate a 2D Visualization of the Brain Connectome Network.

I am trying to understand all the 2D plot options in Slicer with Python. So my question is the following:  
What are all the node classes that can be added in slicer.mrmlScene.AddNewNodeByClass( ? ) ?

Also, if I would like to plot a vtkSpiderPlot() in an existing window of Slicer, would that be possible? Until now I’ve only managed to plot it in a pop up window that uses the OpenGL Visualization ToolKit.

Thank you all in advance!

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 25, 2019, 5:51pm UTC](https://discourse.slicer.org/t/plot-nodes-in-slicer/8553/2 "2019-09-25T17:51:11Z")

</div>

Currently line, scatter, and bar plots are available via the GUI. To show spider plots, you would need to do some Python scripting. I would recommend to show this plot first in a plain VTK render window. Once you have that working, then I can help with making that window show up in the view layout.

---

<div class="post-metadata">

**Author:** ![wieke.prummel](https://avatars.discourse-cdn.com/v4/letter/w/58956e/32.png) [@wieke.prummel](https://discourse.slicer.org/u/wieke.prummel)\
**Post date:** [September 26, 2019, 8:17pm UTC](https://discourse.slicer.org/t/plot-nodes-in-slicer/8553/3 "2019-09-26T20:17:42Z")

</div>

Thank you for your reply Andras.

I am pretty new to VTK and Slicer.

I have generated the spider plot in a plain VTK render window, which is the pop up window I was talking about before. To do so I used vtkRenderer(), vtkRenderWindow(), vtkRenderWindowInteractor().

So as I would like to make that window show up in Slicer you suggest me to use the view layout.  
Should I look at the slicer.app.layoutManager() ? If so, could you help me understand how that should be implemented and what vtkMRML Node to use?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 27, 2019, 10:30pm UTC](https://discourse.slicer.org/t/plot-nodes-in-slicer/8553/4 "2019-09-27T22:30:28Z")

</div>

@Sunderlandkyl could you advise how the view class that you recently added to Slicer could be used for this? Thank you.

---

<div class="post-metadata">

**Author:** ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)\
**Post date:** [September 28, 2019, 12:13am UTC](https://discourse.slicer.org/t/plot-nodes-in-slicer/8553/5 "2019-09-28T00:13:21Z")

</div>

You can add your vtkRenderWindow to a QVTKWidget, and then add that widget to a layout using [qSlicerSingletonViewFactory](https://apidocs.slicer.org/master/classqSlicerSingletonViewFactory.html).

Ex.

- Add view factory to layout manager:

- Add custom layout to layout manager:

- Switch to layout with custom widget:

---

<div class="post-metadata">

**Author:** ![wieke.prummel](https://avatars.discourse-cdn.com/v4/letter/w/58956e/32.png) [@wieke.prummel](https://discourse.slicer.org/u/wieke.prummel)\
**Post date:** [October 1, 2019, 2:52pm UTC](https://discourse.slicer.org/t/plot-nodes-in-slicer/8553/6 "2019-10-01T14:52:13Z")

</div>

Hi @Sunderlandkyl,

Thank you for your response.

I think I am close. I just can’t access QVTKWidget or QVTKRenderWindowInteractor.  
I am using 3D Slicer version 4.10.1-2019-01-16. with qt5.  
Do you know how I can access those ?  
I tried calling defining it like this :

> qWidget = vtk.QVTKWidget()

But I get:

> AttributeError: ‘module’ object has no attribute ‘QVTKWidget’

---

<div class="post-metadata">

**Author:** ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)\
**Post date:** [October 1, 2019, 7:56pm UTC](https://discourse.slicer.org/t/plot-nodes-in-slicer/8553/7 "2019-10-01T19:56:00Z")

</div>

@lassoan Do you know of an alternative to QVTKWidget that is wrapped in python?

Alternatively, is there a better way to embed a vtkRenderWindow() in a QWidget?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 1, 2019, 9:10pm UTC](https://discourse.slicer.org/t/plot-nodes-in-slicer/8553/8 "2019-10-01T21:10:58Z")

</div>

[ctkVTKOpenGLNativeWidget](https://github.com/commontk/CTK/blob/master/Libs/Visualization/VTK/Widgets/ctkVTKOpenGLNativeWidget.h) can be used for this.

---

<div class="post-metadata">

**Author:** ![joinvar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/joinvar/32/66814_2.png) [@joinvar](https://discourse.slicer.org/u/joinvar)\
**Post date:** [July 17, 2023, 1:35am UTC](https://discourse.slicer.org/t/plot-nodes-in-slicer/8553/9 "2023-07-17T01:35:59Z")

</div>

hi, lassoan, When I use ctkVTKOpenGLNativeWidget in python, I encounter a problem. Show “AttributeError: ctkVTKOpenGLNativeWidget has no  
attribute named ‘setRenderWindow’”. Here is a screenshot below.  
 ![(U4$A74Z}7LN~NF45~E1M](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/5/35319bb9bfe08eae6486c8c51be445095b47fde6.png)  
But i noticed that it has been used like this in the ctk source code.

 ![{G{VTHYAFHTIELDH3XWWIPW](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/8/480627d73d1053299fefe2bdc60d15c86da965e8.png)  
And, when I was reviewing the source code in ctk,  
i found that ctkVTKOpenGLNativeWidget may inherit from three classes, and all of the parent classes has a public function setRenderWindow or SetRenderWindow .  
So, I wonder to know if it is not obtainable in python .I am not familiar with python’s wrapper. Thanks a lot.

---

<div class="post-metadata">

**Author:** ![joinvar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/joinvar/32/66814_2.png) [@joinvar](https://discourse.slicer.org/u/joinvar)\
**Post date:** [July 21, 2023, 1:44am UTC](https://discourse.slicer.org/t/plot-nodes-in-slicer/8553/10 "2023-07-21T01:44:49Z")

</div>

@lassoan In addition, i used slicer version is 5.2.2. I can get ctkVTKOpenGLNativeWidget’s setRenderWindow function in a c++ loadable module.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 21, 2023, 4:13am UTC](https://discourse.slicer.org/t/plot-nodes-in-slicer/8553/11 "2023-07-21T04:13:46Z")

</div>

The generic Python-wrapped Qt widget for VTK rendering is `ctk.ctkVTKRenderView()`. A complete example:

```python
widget = ctk.ctkVTKRenderView()
renderer = widget.renderWindow().GetRenderers().GetFirstRenderer()

cylinder = vtk.vtkCylinderSource()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(cylinder.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
renderer.AddActor(actor)

renderer.ResetCamera()
widget.show()

```

---

<div class="post-metadata">

**Author:** ![joinvar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/joinvar/32/66814_2.png) [@joinvar](https://discourse.slicer.org/u/joinvar)\
**Post date:** [July 21, 2023, 5:53am UTC](https://discourse.slicer.org/t/plot-nodes-in-slicer/8553/12 "2023-07-21T05:53:06Z")

</div>

Thank you, I’ll try it.
