Fix IndexError in show_segmentation when fig has no axes #125
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug Report: IndexError in show_segmentation function
Description
The
show_segmentationfunction incellpose_omni/plot.pythrows anIndexErrorwhen called with a figure that has no axes.Error Message
Root Cause
At line 538 in
cellpose_omni/plot.py, the function assumes that any provided figure already has axes:However, when creating a figure with
plt.figure(), no axes are automatically created, causingfig.get_axes()to return an empty list.Reproduction
This issue occurs when calling
show_segmentationwith a figure created using the examples from the documentation:Proposed Fix
Replace line 538 in
cellpose_omni/plot.py:Impact
This affects any user following the documentation examples who creates a figure before calling
show_segmentation. It's particularly problematic in the latest developmental version.Environment
Workaround
Currently, users can work around this by:
Noneas the figure parameter (let the function create its own)fig, ax = plt.subplots()This fix would make the function more robust and consistent with the documentation examples.