# Screen capture of chart

**URL:** <https://discourse.slicer.org/t/screen-capture-of-chart/9195>\
**Category:** Development\
**Created:** [November 18, 2019, 5:35pm UTC](https://discourse.slicer.org/t/screen-capture-of-chart/9195 "2019-11-18T17:35:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dominicrushforth](https://avatars.discourse-cdn.com/v4/letter/d/97f17d/32.png) [@dominicrushforth](https://discourse.slicer.org/u/dominicrushforth)\
**Post date:** [November 18, 2019, 5:35pm UTC](https://discourse.slicer.org/t/screen-capture-of-chart/9195/1 "2019-11-18T17:35:45Z")

</div>

I want to screen capture a chart I’ve generated (using python) for inclusion in a report.

The following code works great for a 3D display…

view = cap.viewFromNode(slicer.mrmlScene.GetNodeByID(‘vtkMRMLViewNode1’))  
cap.captureImageFromView(view, latexFolder + ‘\’ + fileName + ‘3dImage.png’)

but I get just the same result if a chart is being displayed in the display window. I have tried looking for a chart specific view node such as ‘vtkMRMLPlotViewNodePlotView1’ but without any success .

Even with the screen capture widget I can’t figure out how to capture the chart on it’s own - although I can get the chart, with all the other windows, if I use the ‘capture all views’ option. The save button on the interactive chart also doesn’t seem to be working for me.

I am using the nightly build from 11/11 on windows.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 18, 2019, 9:07pm UTC](https://discourse.slicer.org/t/screen-capture-of-chart/9195/2 "2019-11-18T21:07:08Z")

</div>

I’ve updated ScreenCapture module logic so that it can capture plot views. This script will work in Slicer rev28626 and later:

```python
# Get a volume from SampleData and compute its histogram
import SampleData
import numpy as np
volumeNode = SampleData.SampleDataLogic().downloadMRHead()
histogram = np.histogram(arrayFromVolume(volumeNode), bins=50)
chartNode = slicer.util.plot(histogram, xColumnIndex = 1)
chartNode.SetYAxisRangeAuto(False)
chartNode.SetYAxisRange(0, 4e5)

# Capture plot view
viewNodeID = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLPlotViewNode").GetID()
import ScreenCapture
cap = ScreenCapture.ScreenCaptureLogic()
view = cap.viewFromNode(slicer.mrmlScene.GetNodeByID(viewNodeID))
cap.captureImageFromView(view,'c:/tmp/test.png')

```

---

<div class="post-metadata">

**Author:** ![dominicrushforth](https://avatars.discourse-cdn.com/v4/letter/d/97f17d/32.png) [@dominicrushforth](https://discourse.slicer.org/u/dominicrushforth)\
**Post date:** [November 22, 2019, 3:20pm UTC](https://discourse.slicer.org/t/screen-capture-of-chart/9195/3 "2019-11-22T15:20:49Z")

</div>

That’s brilliant, thanks.

It’s now working exactly as I was expecting it to.
