2D visualization in Slicer (Spectrogram, contour plot)


I’m searching for information about 2D visualization in Slicer. For example I can see this doc page but I can’t understand what library is used for 2D plotting? Is it VTK?

In near future I have to decide what library to use to display some matrices in form of Spectrogram and contour plot like in the pictures here

Previously I had some experience of working with QWT library but now when I work with Slicer I think I could replace QWT by some internal Slicer’s visualization library (probably VTK or some other)

Yes, Plotting in Slicer uses VTK (see Documentation/Nightly/Developers/FAQ - Slicer Wiki).

I never used QWT. In theory it looks like it could be added to Slicer’s Qt build but I’m not sure how much work that would vs making the same features in VTK.

Slicer’s transform display functions are a good example of what you can do in Slicer/VTK.

1 Like

Thank you, then I will try VTK for 2D plotting

By the way does Slicer use Matplotlib? Just wondering

It’s a bit clunky but you can do it with something like this:

Or you can use SlicerJupyter.

1 Like

You can create static plots using any of the Python plotting packages (there are literally hundreds of them). Integrating interactions is a bit more tricky.

Visual appearance of QWT plots are about just as rudimentary as VTK (looks like designed by engineers and not artists). So, I’m not sure it would be a significant step up from VTK, and it would require some work to connect it with VTK data structures (that Slicer uses not just for visualization but as data model) and with the Slicer GUI.

We use VTK plots for real-time spectrogram plots of diffuse reflective spectroscopy, see for example here:

It may be better to use VTK plots for interactive visualization and some Python packages for large, complex, static plots.

1 Like