How to get the histogram and area

Hello,
I would like to get the histogram and the area. In the beginning, I follow the Calculating distance using Maurer distance map Topic. But when I copy and paste the script into the Python console. I got the below message. Could you please give me some advice? Thank you very much.

Python 2.7.13 (default, May 16 2019, 14:27:45) [MSC v.1900 64 bit (AMD64)] on win32
>>> modelNode = getNode('VTK Output File')
DLL load failed: The specified module could not be found.
DLL load failed: The specified module could not be found.
DLL load failed: The specified module could not be found.
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Program Files\Slicer 4.10.2\bin\Python\slicer\util.py", line 710, in getNode
    raise MRMLNodeNotFoundException("could not find nodes in the scene by name or id '%s'" % (pattern if (type(pattern) == str) else ""))
MRMLNodeNotFoundException: could not find nodes in the scene by name or id 'VTK Output File'
>>> distanceArrayName = "Signed"
>>> 
>>> # Get distances from point data
>>> import numpy as np
>>> distances = vtk.util.numpy_support.vtk_to_numpy(modelNode.GetPolyData().GetPointData().GetArray(distanceArrayName))
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'modelNode' is not defined
>>> 
>>> # Print basic stats
>>> print("Minimum distance: %f" % min(distances))
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'distances' is not defined
>>> print("Maximum distance: %f" % max(distances))
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'distances' is not defined
>>> print("Mean distance: %f" % np.mean(distances))
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'distances' is not defined
>>> 
>>> # Compute histogram
>>> histogram = np.histogram(distances, bins=100)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'distances' is not defined
>>> 
>>> # Save results to a new table node
>>> tableNode=slicer.mrmlScene.AddNewNodeByClass("vtkMRMLTableNode", modelNode.GetName() + " histogram")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'modelNode' is not defined
>>> updateTableFromArray(tableNode, histogram)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'tableNode' is not defined
>>> tableNode.GetTable().GetColumn(0).SetName("Count")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'tableNode' is not defined
>>> tableNode.GetTable().GetColumn(1).SetName("Intensity")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'tableNode' is not defined
>>> 
>>> # Create plot
>>> 
>>> plotDataNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLPlotDataNode")
>>> plotDataNode.SetAndObserveTableNodeID(tableNode.GetID())
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'SetAndObserveTableNodeID'
>>> plotDataNode.SetXColumnName("Intensity")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'SetXColumnName'
>>> plotDataNode.SetYColumnName("Count")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'SetYColumnName'
>>> 
>>> plotChartNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLPlotChartNode")
>>> plotChartNode.AddAndObservePlotDataNodeID(plotDataNode.GetID())
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'MRMLCorePython.vtkMRMLPlotChartNode' object has no attribute 'AddAndObservePlotDataNodeID'
>>> plotChartNode.SetAttribute("Type", "Bar") # delete this line for line plot
>>> 
>>> # Show plot in layout
>>> 
>>> layoutManager = slicer.app.layoutManager()
>>> layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutFourUpPlotView)
>>> plotWidget = layoutManager.plotWidget(0)
>>> 
>>> plotViewNode = plotWidget.mrmlPlotViewNode()
>>> plotViewNode.SetPlotChartNodeID(plotChartNode.GetID())

This script is not compatible with Slicer 4.10. Let us know if you have any trouble with the latest stable version.

Thank you very much for your quick response. Now I use version 4.11 and I found the error again and the software does not show the Histogram. Picture3

Python 3.6.7 (default, Sep 30 2020, 16:13:32) [MSC v.1924 64 bit (AMD64)] on win32
>>> modelNode = getNode('VTK Output File')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Users\Boriphat\AppData\Local\NA-MIC\Slicer 4.11.20200930\bin\Python\slicer\util.py", line 1137, in getNode
    raise MRMLNodeNotFoundException("could not find nodes in the scene by name or id '%s'" % (pattern if (isinstance(pattern, str)) else ""))
slicer.util.MRMLNodeNotFoundException: could not find nodes in the scene by name or id 'VTK Output File'
>>> distanceArrayName = "Signed"
>>> 
>>> # Get distances from point data
>>> import numpy as np
>>> distances = vtk.util.numpy_support.vtk_to_numpy(modelNode.GetPolyData().GetPointData().GetArray(distanceArrayName))
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'modelNode' is not defined
>>> 
>>> # Print basic stats
>>> print("Minimum distance: %f" % min(distances))
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'distances' is not defined
>>> print("Maximum distance: %f" % max(distances))
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'distances' is not defined
>>> print("Mean distance: %f" % np.mean(distances))
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'distances' is not defined
>>> 
>>> # Compute histogram
>>> histogram = np.histogram(distances, bins=100)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'distances' is not defined
>>> 
>>> # Save results to a new table node
>>> tableNode=slicer.mrmlScene.AddNewNodeByClass("vtkMRMLTableNode", modelNode.GetName() + " histogram")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'modelNode' is not defined
>>> updateTableFromArray(tableNode, histogram)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'tableNode' is not defined
>>> tableNode.GetTable().GetColumn(0).SetName("Count")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'tableNode' is not defined
>>> tableNode.GetTable().GetColumn(1).SetName("Intensity")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'tableNode' is not defined
>>> 
>>> # Create plot
>>> 
>>> plotDataNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLPlotDataNode")
>>> plotDataNode.SetAndObserveTableNodeID(tableNode.GetID())
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'SetAndObserveTableNodeID'
>>> plotDataNode.SetXColumnName("Intensity")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'SetXColumnName'
>>> plotDataNode.SetYColumnName("Count")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'SetYColumnName'
>>> 
>>> plotChartNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLPlotChartNode")
>>> plotChartNode.AddAndObservePlotDataNodeID(plotDataNode.GetID())
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'MRMLCorePython.vtkMRMLPlotChartNode' object has no attribute 'AddAndObservePlotDataNodeID'
>>> plotChartNode.SetAttribute("Type", "Bar") # delete this line for line plot
>>> 
>>> # Show plot in layout
>>> 
>>> layoutManager = slicer.app.layoutManager()
>>> layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutFourUpPlotView)
>>> plotWidget = layoutManager.plotWidget(0)
>>> 
>>> plotViewNode = plotWidget.mrmlPlotViewNode()
>>> plotViewNode.SetPlotChartNodeID(plotChartNode.GetID())
>>> 
>>>

Replace VTK Output File in the example with the actual name of your node.

I replace the VTK output File follow your recommendation and It shows the message. Could you please give me some advice again? Thank you very much for your kindness.

Python 3.6.7 (default, Sep 30 2020, 16:13:32) [MSC v.1924 64 bit (AMD64)] on win32
>>> modelNode = getNode('VTK Output File_6-0')distanceArrayName = "Signed"# Get distances from point dataimport numpy as npdistances = vtk.util.numpy_support.vtk_to_numpy(modelNode.GetPolyData().GetPointData().GetArray(distanceArrayName))# Print basic statsprint("Minimum distance: %f" % min(distances))print("Maximum distance: %f" % max(distances))print("Mean distance: %f" % np.mean(distances))# Compute histogramhistogram = np.histogram(distances, bins=100)# Save results to a new table nodetableNode=slicer.mrmlScene.AddNewNodeByClass("vtkMRMLTableNode", modelNode.GetName() + " histogram")updateTableFromArray(tableNode, histogram)tableNode.GetTable().GetColumn(0).SetName("Count")tableNode.GetTable().GetColumn(1).SetName("Intensity")# Create plotplotDataNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLPlotDataNode")plotDataNode.SetAndObserveTableNodeID(tableNode.GetID())plotDataNode.SetXColumnName("Intensity")plotDataNode.SetYColumnName("Count")plotChartNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLPlotChartNode")plotChartNode.AddAndObservePlotDataNodeID(plotDataNode.GetID())plotChartNode.SetAttribute("Type", "Bar") # delete this line for line plot# Show plot in layoutlayoutManager = slicer.app.layoutManager()layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutFourUpPlotView)plotWidget = layoutManager.plotWidget(0)plotViewNode = plotWidget.mrmlPlotViewNode()plotViewNode.SetPlotChartNodeID(plotChartNode.GetID())
  File "<console>", line 1
    modelNode = getNode('VTK Output File_6-0')distanceArrayName = "Signed"# Get distances from point dataimport numpy as npdistances = vtk.util.numpy_support.vtk_to_numpy(modelNode.GetPolyData().GetPointData().GetArray(distanceArrayName))# Print basic statsprint("Minimum distance: %f" % min(distances))print("Maximum distance: %f" % max(distances))print("Mean distance: %f" % np.mean(distances))# Compute histogramhistogram = np.histogram(distances, bins=100)# Save results to a new table nodetableNode=slicer.mrmlScene.AddNewNodeByClass("vtkMRMLTableNode", modelNode.GetName() + " histogram")updateTableFromArray(tableNode, histogram)tableNode.GetTable().GetColumn(0).SetName("Count")tableNode.GetTable().GetColumn(1).SetName("Intensity")# Create plotplotDataNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLPlotDataNode")plotDataNode.SetAndObserveTableNodeID(tableNode.GetID())plotDataNode.SetXColumnName("Intensity")plotDataNode.SetYColumnName("Count")plotChartNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLPlotChartNode")plotChartNode.AddAndObservePlotDataNodeID(plotDataNode.GetID())plotChartNode.SetAttribute("Type", "Bar") # delete this line for line plot# Show plot in layoutlayoutManager = slicer.app.layoutManager()layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutFourUpPlotView)plotWidget = layoutManager.plotWidget(0)plotViewNode = plotWidget.mrmlPlotViewNode()plotViewNode.SetPlotChartNodeID(plotChartNode.GetID())
                                                              ^
SyntaxError: invalid syntax
>>>

It seems that you have copied the text from somewhere so that the line breaks got lost and everything got into a single line. Use a programming editor, such as Visual Studio Code, for editing code snippets - it usually handles end-of-line character differences well.