# Real time interactive plot in Slicer

**URL:** <https://discourse.slicer.org/t/real-time-interactive-plot-in-slicer/10494>\
**Category:** Development\
**Created:** [March 2, 2020, 3:11pm UTC](https://discourse.slicer.org/t/real-time-interactive-plot-in-slicer/10494 "2020-03-02T15:11:05Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![fpsiddiqui91](https://avatars.discourse-cdn.com/v4/letter/f/53a042/32.png) [@fpsiddiqui91](https://discourse.slicer.org/u/fpsiddiqui91)\
**Post date:** [March 2, 2020, 6:07pm UTC](https://discourse.slicer.org/t/real-time-interactive-plot-in-slicer/10494/2 "2020-03-02T18:07:57Z")

</div>

I went through several examples, like:

> [@Area of segment in a given slice?](https://discourse.slicer.org/t/area-of-segment-in-a-given-slice/1559):
>
> Is there a way to determine the area a segment takes up in a given slice? I’m interested in generating a plot from a CT scan, anterior to posterior, of the area taken up by a segment slice-by-slice (if that makes sense). If you were to do this on a sphere, for example, you’d wind up with a gaussian. (I think, I’d have to double-check the math on that…) Thanks! -Hollister

> [@How can I run the Mesh statistics?](https://discourse.slicer.org/t/how-can-i-run-the-mesh-statistics/2760/2):
>
> You can simply save the file in vtk or vtp file format and that will contain all the computed distances for each point. Note that you can also access all the distance values in Python and compute statistics (histogram, etc). For example, this script shows how to compute and plot histogram: modelNode = getNode('VTK Output File') # Get distances from model node (stored in point data array) import vtk.util.numpy\_support distanceArrayVtk =modelNode.GetPolyData().GetPointData().GetArray('Signed') …

I managed to make a histogram with my Table Node, However, as I update the table Node with my new data, the chart just vanishes. Here is my code for making a histogram:

```
self.plotChartNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLPlotChartNode", "Histogram")
histogram = np.histogram(self.my_DATA, bins=10) # my_DATA is the numpy array containing the data
self.tableNode=slicer.mrmlScene.AddNewNodeByClass("vtkMRMLTableNode","Distance Histogram")
slicer.util.updateTableFromArray(self.tableNode,histogram)
self.tableNode.GetTable().GetColumn(0).SetName("Count")
self.tableNode.GetTable().GetColumn(1).SetName("Intensity")

# Create new plot data series node
self.plotSeriesNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLPlotSeriesNode", "Distance histogram")
self.plotSeriesNode.SetAndObserveTableNodeID(self.tableNode.GetID())
self.plotSeriesNode.SetXColumnName("Intensity")
self.plotSeriesNode.SetYColumnName("Count")
self.plotSeriesNode.SetPlotType(slicer.vtkMRMLPlotSeriesNode.PlotTypeScatterBar)
self.plotSeriesNode.SetMarkerStyle(slicer.vtkMRMLPlotSeriesNode.MarkerStyleNone)

# Add plot to chart
self.plotChartNode.AddAndObservePlotSeriesNodeID(self.plotSeriesNode.GetID())
#self.plotChartNode.AddAndObservePlotDataNodeID(self.DataNode.GetID())

layoutManager=slicer.app.layoutManager()
layoutManager.setLayout (slicer.vtkMRMLLayoutNode.SlicerLayoutFourUpPlotView)
self.plotWidget = layoutManager.plotWidget(0)

self.plotViewNode= self.plotWidget.mrmlPlotViewNode()
self.plotViewNode.SetPlotChartNodeID (self.plotChartNode.GetID())

```

This works fine. However as , my data gets updated, I make a new histogram and update the table node with a new histogram data as:

```
histogram = np.histogram(self.my_DATA, bins=20)

slicer.util.updateTableFromArray(self.tableNode, histogram)
self.plotWidget.update()

```

As soon as my Table node gets updated, I cannot see anything in the chart.  
Can you help me with this? @lassoan may be. Thanks.

Thanks in advance.

---

_[View the full topic](https://discourse.slicer.org/t/real-time-interactive-plot-in-slicer/10494)._
