oncoray / mirp

Medical Image Radiomics Processor
https://oncoray.github.io/mirp/
European Union Public License 1.2
38 stars 11 forks source link

AttributeError: module 'matplotlib.pyplot' has no attribute 'register_cmap' through matplotlib version 3.9.0 #93

Closed smaginmi closed 3 weeks ago

smaginmi commented 1 month ago

Please use the below template to submit your issue:

Expected behavior

I'm running through this TCIA_MIRP notebook and when running this snippet:

images = extract_images(image = image_path, 
                            mask = seg_path,
                            roi_name = "GTV_Mass",
                            image_export_format = "native")
# followed by 

image, mask = images[0]
image[0].show(mask=mask[0], slice_id=10)

And it should just show the image with mask of the mass.

Observed behavior

But instead of the image I get this error msg:

File ~/.venv/lib/python3.10/site-packages/mirp/_images/utilities.py:82, in InteractivePlot.__init__(self, image, mask, slice_id)
     76 # Create mask.
     77 if show_mask:
     78     # Define color map. The custom color map goes from transparent black to semi-transparent green and is
     79     # used as an overlay.
     80 
     81     # Create map and register
---> 82     plt.register_cmap(
     83         cmap=LinearSegmentedColormap(
     84             "mask_cm",
     85             {
     86                 'red': ((0.0, 0.0, 0.0), (1.0, 0.0, 0.0)),
     87                 'green': ((0.0, 0.0, 0.0), (1.0, 0.6, 0.6)),
     88                 'blue': ((0.0, 0.0, 0.0), (1.0, 0.0, 0.0)),
     89                 'alpha': ((0.0, 0.0, 0.0), (1.0, 0.4, 0.4))
     90             }
     91         ),
     92         override_builtin=True
     93     )
     95     self.mask_layer = self.axes.imshow(
     96         self.mask_data[self.slice_index, :, :],
     97         vmin=0.0,
     98         vmax=1.0,
     99         cmap="mask_cm"
    100     )
    101 else:

AttributeError: module 'matplotlib.pyplot' has no attribute 'register_cmap'

Steps to reproduce the problem

The problem seems to stem from the matplotlib version (3.9.0) and downgrading to 3.7.0 and restarting the kernel solves my issue. Here is a similar problem from a different project for reference thread, where their solution is to pin their matplotlib to 3.8.x.

Specifications

alexzwanenburg commented 1 month ago

Thanks for reporting this issue and providing a good indication of how to resolve it.

To do:

alexzwanenburg commented 1 month ago

The breaking change was introduced in matplotlib version 3.9.0