Skip to content

Fixed a bug with drawing an empty Collection - #32228

Open
ayshih wants to merge 3 commits into
matplotlib:mainfrom
ayshih:empty_scatter
Open

Fixed a bug with drawing an empty Collection#32228
ayshih wants to merge 3 commits into
matplotlib:mainfrom
ayshih:empty_scatter

Conversation

@ayshih

@ayshih ayshih commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

PR summary

The PR fixes a bug (fixes #32219) with drawing an empty scatter plot creating a PathCollection with an empty offsets list. Renderers can interpret this (incorrectly) as wanting a single marker with no offset rather than no markers. This PR simply bails out of the draw() call when offsets is empty.

Fixes a bug revealed in #32219, where specifying facecolor="none" (or edgecolor="none") went down a different code path than specifying a color. It turns out that specifying "none" would not be understood as a single color – because zero colors is not equal to one color – which would prevent the optimized drawing of a collection when there is just a single path (allowing the use of draw_markers() instead of draw_path_collection()). I'm going to create an issue for this because it opened up a can of worms. Edit: Ah, #17790 already exists, so I have created #32232 for discussion.

AI Disclosure

No AI was used

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • New and changed code is tested
  • [N/A] Plotting related features are demonstrated in an example
  • [N/A] New features and API changes have release notes
  • [N/A] Documentation complies with general and docstring guidelines

@ayshih ayshih changed the title Fixed a bug with drawing an empty Collection and a second bug with single-path optimization Fixed a bug with drawing an empty Collection Aug 19, 2026
@ayshih
ayshih marked this pull request as ready for review August 19, 2026 13:45
@QuLogic

QuLogic commented Aug 19, 2026

Copy link
Copy Markdown
Member

This makes for a subtle difference; empty scatters won't do any of the bookkeeping that's done for non-empty ones (or even other empty Collection). The main thing there being the open_group/close_group call (which really only affects SVG, I think).

I'm not sure we want to introduce that inconsistency over clarifying backend behaviour.

@ayshih

ayshih commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

For that concern, I could have draw() still call open_group()/close_group() instead of completely bailing out right at the beginning. That said, if get_visible() == False already makes draw() bail out before that bookkeeping, does that bookkeeping actually matter for something that is not supposed to actually draw anything?

@tacaswell

Copy link
Copy Markdown
Member

"Artist marked as not visible" and "artist with null data" are different.

It is worth it's own if block that just does open/close.

@ayshih

ayshih commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Okay, just making sure. Now updated.

Comment thread lib/matplotlib/collections.py
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
@QuLogic QuLogic added this to the v3.11.2 milestone Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ax.scatter([], [], clip_on=False, label=...) renders a ghost marker at the origin/corner when combined with specific styles/limits

3 participants