Skip to content

BUG: Fix non-square wireframe 3D plotting#31750

Merged
tacaswell merged 1 commit into
matplotlib:mainfrom
scottshambaugh:3d_wireframe_error
May 27, 2026
Merged

BUG: Fix non-square wireframe 3D plotting#31750
tacaswell merged 1 commit into
matplotlib:mainfrom
scottshambaugh:3d_wireframe_error

Conversation

@scottshambaugh

@scottshambaugh scottshambaugh commented May 26, 2026

Copy link
Copy Markdown
Contributor

PR summary

Closes #31742

The optimization in #29397 caused issues when the underlying data for 3D wireframe plotting was not square. The test test_wireframe3dasymmetric only made the strides asymmetric and still used square underlying data, so did not catch this. Updated both.

AI Disclosure

Diagnosed with claude's help, manually edited.

PR checklist

@scottshambaugh scottshambaugh added this to the v3.11.0 milestone May 26, 2026
@scottshambaugh scottshambaugh added topic: mplot3d PR: bugfix Pull requests that fix identified bugs labels May 26, 2026
segment_lengths = [len(segment) for segment in segments]
ragged = len(set(segment_lengths)) > 1
if ragged:
# Branch masked / non-masked for speed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did you benchmark this?

@scottshambaugh scottshambaugh May 26, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, for large wireframes the overall function call is 20-30% faster when you skip creating a masked array (mostly due to split set_segments and min below, not in the concat here). The any check is cheap. Part of the reason I want to rip out masked arrays altogether, but that's for later #31008

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If self._segments3d is already and array, you could skip the segment_length calculation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm inclined to merge this as-is and optimize in follow on PRs to get 3.11 unblocked.

segment_lengths = [len(segment) for segment in segments]
ragged = len(set(segment_lengths)) > 1
if ragged:
# Branch masked / non-masked for speed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If self._segments3d is already and array, you could skip the segment_length calculation.

segment_lengths = [len(segment) for segment in segments]
ragged = len(set(segment_lengths)) > 1
if ragged:
# Branch masked / non-masked for speed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm inclined to merge this as-is and optimize in follow on PRs to get 3.11 unblocked.

@tacaswell tacaswell merged commit daa9366 into matplotlib:main May 27, 2026
51 checks passed
@scottshambaugh scottshambaugh mentioned this pull request May 27, 2026
1 task
timhoffm added a commit that referenced this pull request May 27, 2026
…750-on-v3.11.x

Backport PR #31750 on branch v3.11.x (BUG: Fix non-square wireframe 3D plotting)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: bugfix Pull requests that fix identified bugs topic: mplot3d

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 3D wireframe plot error output (3.11.0rc2)

4 participants