Skip to content

Commit 65faf23

Browse files
ksundenmeeseeksmachine
authored andcommitted
Backport PR matplotlib#32228: Fixed a bug with drawing an empty Collection
1 parent b301a38 commit 65faf23

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
@@ -3220,6 +3220,24 @@ def test_scatter_singular_plural_arguments(self):
32203220
facecolors=["#ffffff", "#000000", "#f0f0f0"],
32213221
facecolor="#ffffff")
32223222

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

32243242
def _params(c=None, xsize=2, *, edgecolors=None, **kwargs):
32253243
return (c, edgecolors, kwargs, xsize)

0 commit comments

Comments
 (0)