Skip to content

Gallery example on morphological snakes uses removed attribute 'collections.' #7636

@mkcor

Description

@mkcor

Description:

Since Matplotlib 3.10.0 is out (I can see it was released just ~15 hours ago!), we should stop using the collections attribute for QuadContourSet objects, which is now removed (was deprecated since version 3.8).

We want to update example doc/examples/segmentation/plot_morphsnakes.py (following up on #7630 (comment)). Let's seize this opportunity to update the import of img_as_float as well (i.e., use it via the util subpackage)!

Way to reproduce:

import numpy as np                                                             
import matplotlib.pyplot as plt                                                
from skimage import data, img_as_float                                         
from skimage.segmentation import (                                             
    morphological_chan_vese,                                                   
    morphological_geodesic_active_contour,                                     
    inverse_gaussian_gradient,                                                 
    checkerboard_level_set,                                                    
)

image = img_as_float(data.camera())

# Initial level set                                                            
init_ls = checkerboard_level_set(image.shape, 6)                               
# List with intermediate results for plotting the evolution                    
evolution = []                                                                 
callback = store_evolution_in(evolution)                                       
ls = morphological_chan_vese(                                                  
    image, num_iter=35, init_level_set=init_ls, smoothing=3, iter_callback=callback
)

fig, axes = plt.subplots(2, 2, figsize=(8, 8))                                 
ax = axes.flatten()                                                            
                                                                               
ax[0].imshow(image, cmap="gray")                                               
ax[0].set_axis_off()                                                           
ax[0].contour(ls, [0.5], colors='r')                                           
ax[0].set_title("Morphological ACWE segmentation", fontsize=12)                
                                                                               
ax[1].imshow(ls, cmap="gray")
ax[1].set_axis_off()                                                           
contour = ax[1].contour(evolution[2], [0.5], colors='g')                       
contour.collections[0].set_label("Iteration 2")

Version information:

Jinja2-3.1.4 MarkupSafe-3.0.2 PyWavelets-1.8.0 Pygments-2.18.0 accessible-pygments-0.0.5 alabaster-1.0.0 asttokens-3.0.0 babel-2.16.0 beautifulsoup4-4.12.3 certifi-2024.12.14 charset-normalizer-3.4.0 cloudpickle-3.1.0 comm-0.2.2 contourpy-1.3.1 cycler-0.12.1 dask-2024.12.0 debugpy-1.8.11 decorator-5.1.1 docutils-0.21.2 executing-2.1.0 fonttools-4.55.3 fsspec-2024.10.0 idna-3.10 imagesize-1.4.1 iniconfig-2.0.0 intersphinx-registry-0.2412.7 ipykernel-6.29.5 ipython-8.30.0 ipywidgets-8.1.5 jedi-0.19.2 joblib-1.4.2 jupyter-client-8.6.3 jupyter-core-5.7.2 jupyterlab-widgets-3.0.13 kaleido-0.2.1 kiwisolver-1.4.7 locket-1.0.0 markdown-it-py-3.0.0 matplotlib-3.10.0 matplotlib-inline-0.1.7 mdit-py-plugins-0.4.2 mdurl-0.1.2 myst-parser-4.0.0 nest-asyncio-1.6.0 numpydoc-1.8.0 pandas-2.2.3 parso-0.8.4 partd-1.4.2 pexpect-4.9.0 plotly-5.24.1 pluggy-1.5.0 pooch-1.8.2 prompt_toolkit-3.0.48 psutil-6.1.0 ptyprocess-0.7.0 pure-eval-0.2.3 pydata-sphinx-theme-0.16.0 pyparsing-3.2.0 pytest-8.3.4 pytest-doctestplus-1.3.0 python-dateutil-2.9.0.post0 pytz-2024.2 pyyaml-6.0.2 pyzmq-26.2.0 requests-2.32.3 scikit-learn-1.6.0 seaborn-0.13.2 six-1.17.0 snowballstemmer-2.2.0 soupsieve-2.6 sphinx-8.1.3 sphinx-copybutton-0.5.2 sphinx-gallery-0.18.0 sphinx_design-0.6.1 sphinxcontrib-applehelp-2.0.0 sphinxcontrib-devhelp-2.0.0 sphinxcontrib-htmlhelp-2.1.0 sphinxcontrib-jsmath-1.0.1 sphinxcontrib-qthelp-2.0.0 sphinxcontrib-serializinghtml-2.0.0 stack_data-0.6.3 tabulate-0.9.0 tenacity-9.0.0 threadpoolctl-3.5.0 toolz-1.0.0 tornado-6.4.2 traitlets-5.14.3 typing-extensions-4.12.2 tzdata-2024.2 urllib3-2.2.3 wcwidth-0.2.13 widgetsnbextension-4.0.13

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions