I went through several examples, like:
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.