Using matplotlib for voxel by voxel SUV plot

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?)

For simple interactive plots, I would recommend Slicer’s built-in plotting infrastructure. See example here: Script repository — 3D Slicer documentation

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.

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 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.

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

(Almost 10 years old!).

For advanced plotting these days I have been experimenting with Apache ECharts 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.

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.