# Using matplotlib for voxel by voxel SUV plot

**URL:** <https://discourse.slicer.org/t/using-matplotlib-for-voxel-by-voxel-suv-plot/42315>\
**Category:** Support\
**Tags:** python\
**Created:** [March 26, 2025, 2:27pm UTC](https://discourse.slicer.org/t/using-matplotlib-for-voxel-by-voxel-suv-plot/42315 "2025-03-26T14:27:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CSalt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/csalt/32/79817_2.png) [@CSalt](https://discourse.slicer.org/u/CSalt)\
**Post date:** [March 26, 2025, 2:27pm UTC](https://discourse.slicer.org/t/using-matplotlib-for-voxel-by-voxel-suv-plot/42315/1 "2025-03-26T14:27:58Z")

</div>

I have a segmented PET scan for which I am trying to display voxel by voxel SUV data. I am using the Python console in Slicer and was able to code everything I need, but ran into the error:  
:1: UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown

when I tried to use the command plt.show()  
Is is possible to generate plots like this in slicer? I am open to any other methods, I am just most familiar with matplotlib.

(aside, would this be easier to do with matlab?)

---

<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:** [March 26, 2025, 2:47pm UTC](https://discourse.slicer.org/t/using-matplotlib-for-voxel-by-voxel-suv-plot/42315/2 "2025-03-26T14:47:19Z")

</div>

For simple interactive plots, I would recommend Slicer’s built-in plotting infrastructure. See example here: [Script repository — 3D Slicer documentation](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#slicer-plots-displayed-in-view-layout)

For more complex interactive plots you can use any of the web plotting toolkits. This works, as you can access Slicer functions from JavaScript (by running Python code) and you can call JavaScript functions from Slicer. @pieper has used this technique in some projects, probably you can find examples in his [repositories on github](https://github.com/pieper).

Matplotlib with the `agg` backend is still a simple option for generating static plots. For interactive plots, you can use other backends, but I’m not sure if it is worth the trouble.

Matlab’s cost is hard to justify considering the vast amount of free alternatives. Also, Matlab is just not popular in general (its [TIOBE popularity index](https://www.tiobe.com/tiobe-index/) is around 1% and stagnating/declining in recent years), so if you want people to use your solution or eventually contribute to it then it is not a promising option.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [March 26, 2025, 4:15pm UTC](https://discourse.slicer.org/t/using-matplotlib-for-voxel-by-voxel-suv-plot/42315/3 "2025-03-26T16:15:31Z")

</div>

Also, to show the voxelwise SUV you can make a scalar volume and set it in the foreground over the CT and then set a PET lookup table. This will be more efficient than doing this in matplotlib.

If you really want to use matplotlib, then this approach should still work:

[https://www.slicer.org/wiki/Slicer3:Python#Matplotlib\_plotting\_functionality](https://www.slicer.org/wiki/Slicer3:Python#Matplotlib_plotting_functionality)

(Almost 10 years old!).

For advanced plotting these days I have been experimenting with [Apache ECharts](https://echarts.apache.org/en/index.html) in Slicer and it works well. The examples I have are tied to some PHI so I can’t share but if there’s interest I could make some generic examples.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [March 26, 2025, 4:18pm UTC](https://discourse.slicer.org/t/using-matplotlib-for-voxel-by-voxel-suv-plot/42315/4 "2025-03-26T16:18:23Z")

</div>

BTW, the animated demo of ECharts on their homepage is really cool. I’ll be excited to use it next time I have some plotting to do.
