Skip to content

Handles axes flattening for single subplot case inside camera demo script - #3889

Merged
Mayankm96 merged 3 commits into
isaac-sim:mainfrom
Sgt-Hashtag:main
Dec 28, 2025
Merged

Mayankm96 merged 3 commits into
isaac-sim:mainfrom
Sgt-Hashtag:main

Conversation

@Sgt-Hashtag

@Sgt-Hashtag Sgt-Hashtag commented Oct 30, 2025 •

Copy link
Copy Markdown
Contributor

Description

This PR fixes a bug in the save_images_grid function in scripts/demos/sensors/cameras.py that occurs when displaying a single subplot. The issue stems from matplotlib's behavior where plt.subplots(nrow, ncol) returns a single Axes object for single subplots (when nrow=1 and ncol=1) instead of an array. The original code unconditionally called .flatten() on the axes, which caused an AttributeError when axes was a single object rather than an ndarray.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Screenshots

Please attach before and after screenshots of the change if applicable.

| Before | After |
Screenshot_png before
| ------ | ----- |
Screenshot_png after

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the changelog and the corresponding version in the extension's config/extension.toml file
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@Sgt-Hashtag
Sgt-Hashtag requested a review from ooctipus as a code owner October 30, 2025 00:51
@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Oct 30, 2025

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

This PR fixes a bug in the save_images_grid function in scripts/demos/sensors/cameras.py that occurs when displaying a single subplot. The issue stems from matplotlib's behavior where plt.subplots(nrow, ncol) returns a single Axes object for single subplots (when nrow=1 and ncol=1) instead of an array. The original code unconditionally called .flatten() on the axes, which caused an AttributeError when axes was a single object rather than an ndarray.

The fix adds a type check to handle both cases: if axes is an ndarray, it flattens it as before; otherwise, it wraps the single axis in a numpy array to maintain consistency for the subsequent loop that indexes into the axes array. This change ensures the camera demo visualization function works correctly regardless of whether it's displaying one image or multiple images in a grid layout.

Important Files Changed

Filename Score Overview
scripts/demos/sensors/cameras.py 1/5 Fixed matplotlib axes handling for single subplot case but contains a syntax error (missing closing parenthesis)

Confidence score: 1/5

  • This PR cannot be merged due to a critical syntax error that will prevent the code from running
  • Score is 1/5 because while the logic fix is correct and addresses a real matplotlib edge case, there's a missing closing parenthesis on line 144 that makes the code syntactically invalid
  • The scripts/demos/sensors/cameras.py file requires immediate attention to fix the syntax error before merge

Sequence Diagram

sequenceDiagram
    participant User
    participant Main
    participant AppLauncher
    participant SimulationContext
    participant InteractiveScene
    participant Robot
    participant Camera
    participant TiledCamera
    participant RaycastCamera
    participant ImageSaver

    User->>Main: "Execute script with --enable_cameras"
    Main->>AppLauncher: "Launch Isaac Sim app"
    AppLauncher-->>Main: "Simulation app ready"
    
    Main->>SimulationContext: "Initialize simulation context"
    SimulationContext-->>Main: "Simulation ready"
    
    Main->>SimulationContext: "Set camera view"
    Main->>InteractiveScene: "Create scene with sensors config"
    InteractiveScene->>Robot: "Spawn robot in environments"
    InteractiveScene->>Camera: "Create standard camera sensor"
    InteractiveScene->>TiledCamera: "Create tiled camera sensor"
    InteractiveScene->>RaycastCamera: "Create raycast camera sensor"
    InteractiveScene-->>Main: "Scene setup complete"
    
    Main->>SimulationContext: "Reset simulation"
    Main->>Main: "Start simulation loop"
    
    loop "Simulation Loop (every frame)"
        alt "Reset condition (every 500 iterations)"
            Main->>Robot: "Reset root state and joint positions"
            Main->>InteractiveScene: "Reset scene buffers"
        end
        
        Main->>Robot: "Set joint position targets"
        Main->>InteractiveScene: "Write data to simulation"
        Main->>SimulationContext: "Step simulation"
        Main->>InteractiveScene: "Update sensor buffers"
        
        Main->>Camera: "Get RGB and depth data"
        Camera-->>Main: "Return image data"
        Main->>TiledCamera: "Get RGB and depth data"
        TiledCamera-->>Main: "Return image data"
        Main->>RaycastCamera: "Get depth and normals data"
        RaycastCamera-->>Main: "Return sensor data"
        
        alt "Save images (every 10 iterations)"
            Main->>ImageSaver: "Save RGB comparison grid"
            Main->>ImageSaver: "Save depth comparison grid"
            Main->>ImageSaver: "Save tiled RGB images"
            Main->>ImageSaver: "Save camera RGB images"
        end
    end
Loading

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread scripts/demos/sensors/cameras.py Outdated
if isinstance(axes, np.ndarray):
axes = axes.flatten()
else:
axes = np.array([axes]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

syntax: Missing closing parenthesis - this will cause a syntax error

Suggested change
axes = np.array([axes]
axes = np.array([axes])

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

This review covers only the changes made since the last review, not the entire PR. The developer has successfully addressed the syntax error identified in the previous review by adding the missing closing parenthesis to line 144 in the save_images_grid function. The fix changes axes = np.array([axes] to axes = np.array([axes]), which resolves the critical syntax error that was preventing the camera demo script from running. This function is part of the camera sensor demonstration workflow in Isaac Lab, responsible for creating visualization grids of camera outputs from different sensor configurations including RGB cameras, depth cameras, and raycast cameras.

Important Files Changed

Filename Score Overview
scripts/demos/sensors/cameras.py 5/5 Fixed missing closing parenthesis in save_images_grid function to resolve syntax error

Confidence score: 5/5

  • This PR is safe to merge with minimal risk as it fixes a critical syntax error
  • Score reflects a simple, well-targeted fix that addresses the exact issue identified in the previous review with no additional complexity
  • No files require special attention as this is a straightforward syntax correction

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

This review covers only the changes made since the last review, not the entire PR. The developer has fixed a critical syntax error that was identified in the previous review by adding the missing closing parenthesis on line 144. The change corrects axes = np.array([axes to axes = np.array([axes]), which resolves the syntax error that would have prevented the code from running. This completes the bug fix for matplotlib's axes flattening behavior when dealing with single subplots in the save_images_grid function.

Important Files Changed

Filename Score Overview
scripts/demos/sensors/cameras.py 5/5 Fixed syntax error by adding missing closing parenthesis to complete the axes array wrapping

Confidence score: 5/5

  • This PR is safe to merge with minimal risk as it only fixes a syntax error
  • Score reflects a simple syntax correction that resolves the compilation issue without changing logic
  • No files require special attention as this is a straightforward syntax fix

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@Mayankm96

Copy link
Copy Markdown
Contributor

Thank you for the fix!

@Mayankm96 Mayankm96 changed the title Fix axes flattening for single subplot case Fixes axes flattening for single subplot case inside camera demo script Dec 28, 2025
@Mayankm96 Mayankm96 changed the title Fixes axes flattening for single subplot case inside camera demo script Handles axes flattening for single subplot case inside camera demo script Dec 28, 2025
@Mayankm96
Mayankm96 merged commit a81f7ec into isaac-sim:main Dec 28, 2025
thiagolages pushed a commit to thiagolages/isaac-lab that referenced this pull request Jan 6, 2026
…ript (isaac-sim#3889)

# Description

This PR fixes a bug in the `save_images_grid` function in
`scripts/demos/sensors/cameras.py` that occurs when displaying a single
subplot. The issue stems from matplotlib's behavior where
plt.subplots(nrow, ncol) returns a single Axes object for single
subplots (when nrow=1 and ncol=1) instead of an array. The original code
unconditionally called .flatten() on the axes, which caused an
AttributeError when axes was a single object rather than an ndarray.

## Type of change

- Bug fix (non-breaking change which fixes an issue)

## Screenshots

Please attach before and after screenshots of the change if applicable.


| Before | After |
<img width="1116" height="502" alt="Screenshot_png before"
src="https://github.com/user-attachments/assets/6d0b7add-ddad-4c9a-8614-d7a75e889769"
/>
| ------ | ----- |
<img width="1116" height="502" alt="Screenshot_png after"
src="https://github.com/user-attachments/assets/24862e7b-4431-4e21-81ea-2cfefa03b127"
/>



## Checklist

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [ ] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------

Signed-off-by: Abhirup Das <[email protected]>
Edify0991 pushed a commit to Edify0991/IsaacLab that referenced this pull request Jan 14, 2026
…ript (isaac-sim#3889)

# Description

This PR fixes a bug in the `save_images_grid` function in
`scripts/demos/sensors/cameras.py` that occurs when displaying a single
subplot. The issue stems from matplotlib's behavior where
plt.subplots(nrow, ncol) returns a single Axes object for single
subplots (when nrow=1 and ncol=1) instead of an array. The original code
unconditionally called .flatten() on the axes, which caused an
AttributeError when axes was a single object rather than an ndarray.

## Type of change

- Bug fix (non-breaking change which fixes an issue)

## Screenshots

Please attach before and after screenshots of the change if applicable.


| Before | After |
<img width="1116" height="502" alt="Screenshot_png before"
src="https://github.com/user-attachments/assets/6d0b7add-ddad-4c9a-8614-d7a75e889769"
/>
| ------ | ----- |
<img width="1116" height="502" alt="Screenshot_png after"
src="https://github.com/user-attachments/assets/24862e7b-4431-4e21-81ea-2cfefa03b127"
/>



## Checklist

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [ ] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------

Signed-off-by: Abhirup Das <[email protected]>
nitesh-subedi pushed a commit to nitesh-subedi/IsaacLab that referenced this pull request Feb 5, 2026
…ript (isaac-sim#3889)

# Description

This PR fixes a bug in the `save_images_grid` function in
`scripts/demos/sensors/cameras.py` that occurs when displaying a single
subplot. The issue stems from matplotlib's behavior where
plt.subplots(nrow, ncol) returns a single Axes object for single
subplots (when nrow=1 and ncol=1) instead of an array. The original code
unconditionally called .flatten() on the axes, which caused an
AttributeError when axes was a single object rather than an ndarray.

## Type of change

- Bug fix (non-breaking change which fixes an issue)

## Screenshots

Please attach before and after screenshots of the change if applicable.


| Before | After |
<img width="1116" height="502" alt="Screenshot_png before"
src="https://github.com/user-attachments/assets/6d0b7add-ddad-4c9a-8614-d7a75e889769"
/>
| ------ | ----- |
<img width="1116" height="502" alt="Screenshot_png after"
src="https://github.com/user-attachments/assets/24862e7b-4431-4e21-81ea-2cfefa03b127"
/>



## Checklist

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [ ] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------

Signed-off-by: Abhirup Das <[email protected]>
csj-275 pushed a commit to csj-275/IsaacLab that referenced this pull request Jul 8, 2026
…ript (isaac-sim#3889)

# Description

This PR fixes a bug in the `save_images_grid` function in
`scripts/demos/sensors/cameras.py` that occurs when displaying a single
subplot. The issue stems from matplotlib's behavior where
plt.subplots(nrow, ncol) returns a single Axes object for single
subplots (when nrow=1 and ncol=1) instead of an array. The original code
unconditionally called .flatten() on the axes, which caused an
AttributeError when axes was a single object rather than an ndarray.

## Type of change

- Bug fix (non-breaking change which fixes an issue)

## Screenshots

Please attach before and after screenshots of the change if applicable.


| Before | After |
<img width="1116" height="502" alt="Screenshot_png before"
src="https://github.com/user-attachments/assets/6d0b7add-ddad-4c9a-8614-d7a75e889769"
/>
| ------ | ----- |
<img width="1116" height="502" alt="Screenshot_png after"
src="https://github.com/user-attachments/assets/24862e7b-4431-4e21-81ea-2cfefa03b127"
/>



## Checklist

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [ ] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------

Signed-off-by: Abhirup Das <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants