Bar charts with categorical data

vtkMRMLChartNode is no longer supported in Slicer 5 - how are we supposed to realize somting like

image

as it was (is) described in

https://www.slicer.org/wiki/Documentation/Nightly/Developers/Charts

?
Thank you.

Here’s how I approached plotting recenetly.

In the last line of that gist you can set plot_type='bar' to get a bar chart.

Thank you.
`How would you set the x axis labels (“tissue”, “bone” etc) in your

# Use set_plot_data to update what is shown in the plot view:
slicer_plot_data.set_plot_data(np.random.normal(size=(10,2)))

line? Could you even set the bar colors?

There is a labels argument in set_plot_data but it doesn’t appear to show labels at the bottom, but rather only when you mouse over the bars.

I don’t know if there is a way to set colors of individual bars they way you show above.

If you see a way to do either of these things then please share :slight_smile:
It may be a limitation in vtkMRMLPlotChartNode’s bar plotting functionality.

1 Like

There’s a lot of underlying functionality and it could be extended and exposed in Slicer.

If you are feeling adventurous this pyqtgraph example apparently works.

But maybe the safest and easiest would be to use maplotlib maybe with seaborn. It’s not fully integrated with slicer though, so some extra work would be required to make it show up in a layout.

3 Likes

Thanks, Steve.
Very interesting links.
This is to make CIP_ParenchymaAnalysis fully compatible again …
Would it not be better to have a simple slicer.util based solution for such a simple and frequently used graph if vtkMRMLChartNode is suddenly not supported any longer? Even analyzing this has cost hours.

Yes, I agree it would be good to have a solid answer to make this easy. Making these scientific visualizations is a complicated topic and all the options are incomplete or have drawbacks of one kind or another. My approach would be to make it easy to use one of the mainstream packages like seaborn for this purpose, although extending the VTK-based approach is also an option.

1 Like