Last active
January 31, 2021 16:29
-
-
Save bloyl/c3bf0dd584ed675c3e1d3e6c2129e1be to your computer and use it in GitHub Desktop.
slicer plot test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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