Skip to content

Fix bug with show2D not rendering with single plot#2327

Merged
lauramurgatroyd merged 5 commits into
masterfrom
show2D_plots
May 29, 2026
Merged

Fix bug with show2D not rendering with single plot#2327
lauramurgatroyd merged 5 commits into
masterfrom
show2D_plots

Conversation

@lauramurgatroyd
Copy link
Copy Markdown
Member

@lauramurgatroyd lauramurgatroyd commented May 15, 2026

Description

Fixes #2326
show2D wasn't working with a single plot because plt.subplots was not returning an array in that case.
Updated to use squeeze=False kwarg to ensure an array is always returned: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html

Also updated to:

  • Delete the 'extra' axes instead of hiding them
  • Make use of .flat instead of .flatten()

Example Usage

Running https://github.com/TomographicImaging/CIL-Demos/blob/main/demos/1_Introduction/03_preprocessing.ipynb

Contribution Notes

  • The content of this Pull Request (the Contribution) is intentionally submitted for inclusion in CIL (the Work) under the terms and conditions of the Apache-2.0 License
  • I confirm that the contribution does not violate any intellectual property rights of third parties

Testing you performed

Note: no unit tests cover this
Run https://github.com/TomographicImaging/CIL-Demos/blob/main/demos/1_Introduction/03_preprocessing.ipynb
to test show2D behaviour with different numbers of plots

Also edited one of the prints to make sure it still worked when we had figures across multiple rows where one row is incomplete e.g.
image

Compared behaviour to v25.0.0 and made sure it matched it

Related issues/links

Checklist

  • I have performed a self-review of my code
  • I have added docstrings in line with the guidance in the developer guide
  • I have updated the relevant documentation
  • I have implemented unit tests that cover any new or modified functionality
  • CHANGELOG.md has been updated with any functionality change
  • Request review from all relevant developers

--->

@lauramurgatroyd lauramurgatroyd requested a review from gfardell May 15, 2026 16:02
Comment thread Wrappers/Python/cil/utilities/display.py Outdated
Copy link
Copy Markdown
Member

@gfardell gfardell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!

@lauramurgatroyd
Copy link
Copy Markdown
Member Author

Note: only failure is expected docker failure currently on master

@lauramurgatroyd lauramurgatroyd merged commit d0a9250 into master May 29, 2026
7 of 8 checks passed
@lauramurgatroyd lauramurgatroyd deleted the show2D_plots branch May 29, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show2D with only one plot fails with AttributeError

2 participants