Skip to content

Commit 767a089

Browse files
authored
Merge pull request #32228 from ayshih/empty_scatter
Fixed a bug with drawing an empty Collection
2 parents acfff0d + 886fc82 commit 767a089

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

lib/matplotlib/collections.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,12 @@ def draw(self, renderer):
363363
return
364364
renderer.open_group(self.__class__.__name__, self.get_gid())
365365

366+
# Bail if the collection does not have any offsets (e.g., an empty scatter plot)
367+
if len(self.get_offsets()) == 0:
368+
renderer.close_group(self.__class__.__name__)
369+
self.stale = False
370+
return
371+
366372
self.update_scalarmappable()
367373

368374
transform, offset_trf, offsets, paths = self._prepare_points()

lib/matplotlib/tests/test_axes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3217,6 +3217,24 @@ def test_scatter_singular_plural_arguments(self):
32173217
facecolors=["#ffffff", "#000000", "#f0f0f0"],
32183218
facecolor="#ffffff")
32193219

3220+
@pytest.mark.parametrize('edgecolor, facecolor, linestyle',
3221+
[('red', 'blue', 'solid'),
3222+
('red', 'blue', 'dashed'),
3223+
('red', 'none', 'solid'),
3224+
('none', 'blue', 'solid')])
3225+
@check_figures_equal()
3226+
def test_empty_scatter(self, fig_test, fig_ref, edgecolor, facecolor, linestyle):
3227+
# Verify that a spurious marker is not plotted in the bottom-left corner
3228+
# https://github.com/matplotlib/matplotlib/issues/32219
3229+
ax_test = fig_test.subplots()
3230+
ax_test.scatter([], [], ec=edgecolor, fc=facecolor, ls=linestyle, clip_on=False)
3231+
ax_test.set_xlim(0, 1)
3232+
ax_test.set_ylim(0, 1)
3233+
3234+
ax_ref = fig_ref.subplots()
3235+
ax_ref.set_xlim(0, 1)
3236+
ax_ref.set_ylim(0, 1)
3237+
32203238

32213239
def _params(c=None, xsize=2, *, edgecolors=None, **kwargs):
32223240
return (c, edgecolors, kwargs, xsize)

0 commit comments

Comments
 (0)