diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 703a77ee593a..7d1a687f465d 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -363,6 +363,12 @@ def draw(self, renderer): return renderer.open_group(self.__class__.__name__, self.get_gid()) + # Bail if the collection does not have any offsets (e.g., an empty scatter plot) + if len(self.get_offsets()) == 0: + renderer.close_group(self.__class__.__name__) + self.stale = False + return + self.update_scalarmappable() transform, offset_trf, offsets, paths = self._prepare_points() diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index fb3cae3474f1..5ecca195ec24 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -3217,6 +3217,24 @@ def test_scatter_singular_plural_arguments(self): facecolors=["#ffffff", "#000000", "#f0f0f0"], facecolor="#ffffff") + @pytest.mark.parametrize('edgecolor, facecolor, linestyle', + [('red', 'blue', 'solid'), + ('red', 'blue', 'dashed'), + ('red', 'none', 'solid'), + ('none', 'blue', 'solid')]) + @check_figures_equal() + def test_empty_scatter(self, fig_test, fig_ref, edgecolor, facecolor, linestyle): + # Verify that a spurious marker is not plotted in the bottom-left corner + # https://github.com/matplotlib/matplotlib/issues/32219 + ax_test = fig_test.subplots() + ax_test.scatter([], [], ec=edgecolor, fc=facecolor, ls=linestyle, clip_on=False) + ax_test.set_xlim(0, 1) + ax_test.set_ylim(0, 1) + + ax_ref = fig_ref.subplots() + ax_ref.set_xlim(0, 1) + ax_ref.set_ylim(0, 1) + def _params(c=None, xsize=2, *, edgecolors=None, **kwargs): return (c, edgecolors, kwargs, xsize)