Skip to content

Instantly share code, notes, and snippets.

@bloyl
Last active Jan 31, 2021
Embed
What would you like to do?
slicer plot test
import numpy as np
tbl_data = np.zeros((2, 100))
tbl_data[0] = 1000 + np.arange(100)
tbl_data[1] = 3 * np.arange(100)
tableNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLTableNode')
updateTableFromArray(tableNode, tbl_data.transpose())
tableNode.GetTable().GetColumn(0).SetName('X')
tableNode.GetTable().GetColumn(1).SetName('Y')
#Create chart and add plot
plotChartNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLPlotChartNode')
# add each line plot
plotSeriesNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLPlotSeriesNode', 'Test')
plotSeriesNode.SetAndObserveTableNodeID(tableNode.GetID())
plotSeriesNode.SetXColumnName('X')
plotSeriesNode.SetYColumnName('Y')
plotSeriesNode.SetPlotType(plotSeriesNode.PlotTypeLine)
plotSeriesNode.SetColor(0, 0.6, 1.0)
plotChartNode.AddAndObservePlotSeriesNodeID(plotSeriesNode.GetID())
#Show plot in layout
slicer.modules.plots.logic().ShowChartInLayout(plotChartNode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment