From 84924454784a446d79247f617a22b015f163213f Mon Sep 17 00:00:00 2001 From: Chahak Mehta Date: Sun, 19 Feb 2023 11:31:25 -0600 Subject: [PATCH 01/10] Toy working example for scatter markersize --- lib/matplotlib/axes/_axes.py | 7 ++++++- lib/matplotlib/collections.py | 14 +++++++++----- lib/mpl_toolkits/mplot3d/art3d.py | 4 ++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 91aba7c1bdac..30e8ece4c29a 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -4476,7 +4476,7 @@ def invalid_shape_exception(csize, xsize): @_docstring.interpd def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, *, - edgecolors=None, plotnonfinite=False, **kwargs): + edgecolors=None, plotnonfinite=False, markersize=None, **kwargs): """ A scatter plot of *y* vs. *x* with varying marker size and/or color. @@ -4611,6 +4611,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, s = (20 if mpl.rcParams['_internal.classic_mode'] else mpl.rcParams['lines.markersize'] ** 2.0) s = np.ma.ravel(s) + scaling = 2 if (len(s) not in (1, x.size) or (not np.issubdtype(s.dtype, np.floating) and not np.issubdtype(s.dtype, np.integer))): @@ -4618,6 +4619,9 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, "s must be a scalar, " "or float array-like with the same size as x and y") + if markersize is not None: + s = np.ma.ravel(markersize) + scaling = 1 # get the original edgecolor the user passed before we normalize orig_edgecolor = edgecolors if edgecolors is None: @@ -4696,6 +4700,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, collection = mcoll.PathCollection( (path,), scales, + scaling=scaling, facecolors=colors, edgecolors=edgecolors, linewidths=linewidths, diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index a70e547ef849..9ff654737c47 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -935,6 +935,7 @@ class _CollectionWithSizes(Collection): Base class for collections that have an array of sizes. """ _factor = 1.0 + _scaling = 2 def get_sizes(self): """ @@ -947,7 +948,7 @@ def get_sizes(self): """ return self._sizes - def set_sizes(self, sizes, dpi=72.0): + def set_sizes(self, sizes, dpi=72.0, scaling=2): """ Set the sizes of each member of the collection. @@ -959,13 +960,16 @@ def set_sizes(self, sizes, dpi=72.0): dpi : float, default: 72 The dpi of the canvas. """ + self._scaling = scaling if sizes is None: self._sizes = np.array([]) self._transforms = np.empty((0, 3, 3)) else: self._sizes = np.asarray(sizes) self._transforms = np.zeros((len(self._sizes), 3, 3)) - scale = np.sqrt(self._sizes) * dpi / 72.0 * self._factor + s = np.sqrt(self._sizes) if scaling == 2 else self._sizes + scale = s * dpi / 72.0 * self._factor + # scale = self._sizes * dpi / 72.0 * self._factor self._transforms[:, 0, 0] = scale self._transforms[:, 1, 1] = scale self._transforms[:, 2, 2] = 1.0 @@ -973,7 +977,7 @@ def set_sizes(self, sizes, dpi=72.0): @artist.allow_rasterization def draw(self, renderer): - self.set_sizes(self._sizes, self.figure.dpi) + self.set_sizes(self._sizes, self.figure.dpi, self._scaling) super().draw(renderer) @@ -982,7 +986,7 @@ class PathCollection(_CollectionWithSizes): A collection of `~.path.Path`\s, as created by e.g. `~.Axes.scatter`. """ - def __init__(self, paths, sizes=None, **kwargs): + def __init__(self, paths, sizes=None, scaling=2, **kwargs): """ Parameters ---------- @@ -998,7 +1002,7 @@ def __init__(self, paths, sizes=None, **kwargs): super().__init__(**kwargs) self.set_paths(paths) - self.set_sizes(sizes) + self.set_sizes(sizes, scaling=scaling) self.stale = True def set_paths(self, paths): diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index 20a1566d31a0..163baac76759 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -688,8 +688,8 @@ def set_3d_properties(self, zs, zdir): self._vzs = None self.stale = True - def set_sizes(self, sizes, dpi=72.0): - super().set_sizes(sizes, dpi) + def set_sizes(self, sizes, dpi=72.0, scaling=2): + super().set_sizes(sizes, dpi=dpi, scaling=scaling) if not self._in_draw: self._sizes3d = sizes From 46b3bff57c29512b059e4ed15eb55d3f86db2bd7 Mon Sep 17 00:00:00 2001 From: Chahak Mehta Date: Sat, 25 Feb 2023 21:00:58 -0600 Subject: [PATCH 02/10] Add a working version for markersize in scatter --- lib/matplotlib/axes/_axes.py | 20 +++++++++++++++----- lib/matplotlib/collections.py | 19 +++++++++++-------- lib/mpl_toolkits/mplot3d/art3d.py | 4 ++-- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 30e8ece4c29a..fea317b46702 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -4568,6 +4568,11 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, or ``nan``). If ``True`` the points are drawn with the *bad* colormap color (see `.Colormap.set_bad`). + markersize : float or array-like, shape (n, ), optional + The marker size in points. This differs from `s` as it sets the + size directly in points instead of points**2. `s` is used by + default to set the size if neither are passed. + Returns ------- `~matplotlib.collections.PathCollection` @@ -4607,11 +4612,19 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, if x.size != y.size: raise ValueError("x and y must be the same size") + if s is not None and markersize is not None: + raise ValueError( + "Only one of s or markersize should be passed. " + "Please refer to the docs for more details about usage.") + if s is None: s = (20 if mpl.rcParams['_internal.classic_mode'] else mpl.rcParams['lines.markersize'] ** 2.0) s = np.ma.ravel(s) - scaling = 2 + markerscale = 2 + if markersize is not None: + s = np.ma.ravel(markersize) + markerscale = 1 if (len(s) not in (1, x.size) or (not np.issubdtype(s.dtype, np.floating) and not np.issubdtype(s.dtype, np.integer))): @@ -4619,9 +4632,6 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, "s must be a scalar, " "or float array-like with the same size as x and y") - if markersize is not None: - s = np.ma.ravel(markersize) - scaling = 1 # get the original edgecolor the user passed before we normalize orig_edgecolor = edgecolors if edgecolors is None: @@ -4700,7 +4710,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, collection = mcoll.PathCollection( (path,), scales, - scaling=scaling, + markerscale=markerscale, facecolors=colors, edgecolors=edgecolors, linewidths=linewidths, diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 9ff654737c47..609b63cf6596 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -935,7 +935,7 @@ class _CollectionWithSizes(Collection): Base class for collections that have an array of sizes. """ _factor = 1.0 - _scaling = 2 + _markerscale = 2 def get_sizes(self): """ @@ -948,7 +948,7 @@ def get_sizes(self): """ return self._sizes - def set_sizes(self, sizes, dpi=72.0, scaling=2): + def set_sizes(self, sizes, dpi=72.0, markerscale=2): """ Set the sizes of each member of the collection. @@ -959,17 +959,20 @@ def set_sizes(self, sizes, dpi=72.0, scaling=2): value is the 'area' of the element. dpi : float, default: 72 The dpi of the canvas. + markerscale : int, default: 2 + Scaling factor used to set the size as points or points**2. + Default value is set as 2 used for `s` and changed to 1 if + `markersize` is provided instead of `s`. """ - self._scaling = scaling + self._markerscale = markerscale if sizes is None: self._sizes = np.array([]) self._transforms = np.empty((0, 3, 3)) else: self._sizes = np.asarray(sizes) self._transforms = np.zeros((len(self._sizes), 3, 3)) - s = np.sqrt(self._sizes) if scaling == 2 else self._sizes + s = np.sqrt(self._sizes) if markerscale == 2 else self._sizes scale = s * dpi / 72.0 * self._factor - # scale = self._sizes * dpi / 72.0 * self._factor self._transforms[:, 0, 0] = scale self._transforms[:, 1, 1] = scale self._transforms[:, 2, 2] = 1.0 @@ -977,7 +980,7 @@ def set_sizes(self, sizes, dpi=72.0, scaling=2): @artist.allow_rasterization def draw(self, renderer): - self.set_sizes(self._sizes, self.figure.dpi, self._scaling) + self.set_sizes(self._sizes, self.figure.dpi, self._markerscale) super().draw(renderer) @@ -986,7 +989,7 @@ class PathCollection(_CollectionWithSizes): A collection of `~.path.Path`\s, as created by e.g. `~.Axes.scatter`. """ - def __init__(self, paths, sizes=None, scaling=2, **kwargs): + def __init__(self, paths, sizes=None, markerscale=2, **kwargs): """ Parameters ---------- @@ -1002,7 +1005,7 @@ def __init__(self, paths, sizes=None, scaling=2, **kwargs): super().__init__(**kwargs) self.set_paths(paths) - self.set_sizes(sizes, scaling=scaling) + self.set_sizes(sizes, markerscale=markerscale) self.stale = True def set_paths(self, paths): diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index 163baac76759..6453e4b4eda2 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -688,8 +688,8 @@ def set_3d_properties(self, zs, zdir): self._vzs = None self.stale = True - def set_sizes(self, sizes, dpi=72.0, scaling=2): - super().set_sizes(sizes, dpi=dpi, scaling=scaling) + def set_sizes(self, sizes, dpi=72.0, markerscale=2): + super().set_sizes(sizes, dpi=dpi, markerscale=markerscale) if not self._in_draw: self._sizes3d = sizes From e9f33bbca6e526fe387cf2cd315a5d2a2b1e07db Mon Sep 17 00:00:00 2001 From: Chahak Mehta Date: Sat, 25 Feb 2023 21:02:27 -0600 Subject: [PATCH 03/10] Update pyplot --- lib/matplotlib/pyplot.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 47b019bd714a..a2e8e45781fe 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -3588,6 +3588,7 @@ def scatter( edgecolors: Literal["face", "none"] | ColorType | Sequence[ColorType] | None = None, plotnonfinite: bool = False, data=None, + markersize: int | None = None, **kwargs, ) -> PathCollection: __ret = gca().scatter( @@ -3604,6 +3605,7 @@ def scatter( linewidths=linewidths, edgecolors=edgecolors, plotnonfinite=plotnonfinite, + markersize=markersize, **({"data": data} if data is not None else {}), **kwargs, ) From 1c9576df45aa7f7baf63c97854d2dace1f949e00 Mon Sep 17 00:00:00 2001 From: Chahak Mehta Date: Mon, 13 Mar 2023 21:40:40 -0500 Subject: [PATCH 04/10] Add markersize alias for s and markerscale kwarg --- lib/matplotlib/axes/_axes.py | 24 +++++++-------- lib/matplotlib/collections.py | 37 +++++++++++++++++++----- lib/matplotlib/tests/test_collections.py | 22 ++++++++++++++ 3 files changed, 62 insertions(+), 21 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index fea317b46702..905d7fb3456c 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -4476,7 +4476,7 @@ def invalid_shape_exception(csize, xsize): @_docstring.interpd def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, *, - edgecolors=None, plotnonfinite=False, markersize=None, **kwargs): + edgecolors=None, plotnonfinite=False, markerscale=2, **kwargs): """ A scatter plot of *y* vs. *x* with varying marker size and/or color. @@ -4568,10 +4568,9 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, or ``nan``). If ``True`` the points are drawn with the *bad* colormap color (see `.Colormap.set_bad`). - markersize : float or array-like, shape (n, ), optional - The marker size in points. This differs from `s` as it sets the - size directly in points instead of points**2. `s` is used by - default to set the size if neither are passed. + markerscale : 1 or 2, optional, default: 2 + Scaling factor used to set the size as points or points**2. + Default value is set as 2 to set the size values as points**2. Returns ------- @@ -4612,19 +4611,18 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, if x.size != y.size: raise ValueError("x and y must be the same size") - if s is not None and markersize is not None: + if s is not None and 'markersize' in kwargs: raise ValueError( - "Only one of s or markersize should be passed. " + "Only one of `s` or `markersize` should be passed. " "Please refer to the docs for more details about usage.") if s is None: - s = (20 if mpl.rcParams['_internal.classic_mode'] else - mpl.rcParams['lines.markersize'] ** 2.0) + if 'markersize' not in kwargs: + s = (20 if mpl.rcParams['_internal.classic_mode'] else + mpl.rcParams['lines.markersize'] ** 2.0) + else: + s = kwargs.pop('markersize') s = np.ma.ravel(s) - markerscale = 2 - if markersize is not None: - s = np.ma.ravel(markersize) - markerscale = 1 if (len(s) not in (1, x.size) or (not np.issubdtype(s.dtype, np.floating) and not np.issubdtype(s.dtype, np.integer))): diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 609b63cf6596..a0ff26fd6daa 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -930,24 +930,43 @@ def update_from(self, other): self.stale = True +@_api.define_aliases({ + "sizes": ["s", "markersize"] +}) class _CollectionWithSizes(Collection): """ Base class for collections that have an array of sizes. """ _factor = 1.0 - _markerscale = 2 def get_sizes(self): """ - Return the sizes ('areas') of the elements in the collection. + Return the sizes of the elements in the collection. + + The sizes of the elements in the collection will be returned in + the last set scale of the markers, i.e. if the markerscale was + set to 1 then the sizes are set in points and if markerscale was + set to 2 then the sizes returned are such that the marker size is + in points**2. Returns ------- array - The 'area' of each element. + The 'size' of each element. """ return self._sizes + def get_markerscale(self): + """ + Return the scale used for marker sizing. + + Returns + ------- + int + The scale used to set the marker sizes. + """ + return self._markerscale + def set_sizes(self, sizes, dpi=72.0, markerscale=2): """ Set the sizes of each member of the collection. @@ -959,11 +978,11 @@ def set_sizes(self, sizes, dpi=72.0, markerscale=2): value is the 'area' of the element. dpi : float, default: 72 The dpi of the canvas. - markerscale : int, default: 2 - Scaling factor used to set the size as points or points**2. - Default value is set as 2 used for `s` and changed to 1 if - `markersize` is provided instead of `s`. + markerscale : 1 or 2, default: 2 + Scaling factor used to set the size as points (1) or points**2 (2). """ + # breakpoint() + print(markerscale) self._markerscale = markerscale if sizes is None: self._sizes = np.array([]) @@ -971,7 +990,7 @@ def set_sizes(self, sizes, dpi=72.0, markerscale=2): else: self._sizes = np.asarray(sizes) self._transforms = np.zeros((len(self._sizes), 3, 3)) - s = np.sqrt(self._sizes) if markerscale == 2 else self._sizes + s = np.sqrt(self._sizes) if self._markerscale == 2 else self._sizes scale = s * dpi / 72.0 * self._factor self._transforms[:, 0, 0] = scale self._transforms[:, 1, 1] = scale @@ -999,6 +1018,8 @@ def __init__(self, paths, sizes=None, markerscale=2, **kwargs): The factor by which to scale each drawn `~.path.Path`. One unit squared in the Path's data space is scaled to be ``sizes**2`` points when rendered. + markerscale : 1 or 2, default: 2 + Scaling factor used to set the size as points (1) or points**2 (2). **kwargs Forwarded to `.Collection`. """ diff --git a/lib/matplotlib/tests/test_collections.py b/lib/matplotlib/tests/test_collections.py index 56a9c688af1f..3dd3181ea3be 100644 --- a/lib/matplotlib/tests/test_collections.py +++ b/lib/matplotlib/tests/test_collections.py @@ -1216,3 +1216,25 @@ def test_striped_lines(fig_test, fig_ref, gapcolor): for x, gcol, ls in zip(x, itertools.cycle(gapcolor), itertools.cycle(linestyles)): ax_ref.axvline(x, 0, 1, linestyle=ls, gapcolor=gcol, alpha=0.5) + + +@check_figures_equal(extensions=["png"]) +def test_markerscale(fig_test, fig_ref): + ax_test = fig_test.add_subplot() + ax_ref = fig_ref.add_subplot() + + x = np.arange(1, 6)**2 + + ax_test.scatter(x, x, s=x, markerscale=1) + ax_ref.scatter(x, x, s=x**2, markerscale=2) + + +@check_figures_equal(extensions=["png"]) +def test_markersize_alias(fig_test, fig_ref): + ax_test = fig_test.add_subplot() + ax_ref = fig_ref.add_subplot() + + x = np.arange(1, 6)**2 + + ax_test.scatter(x, x, s=x) + ax_ref.scatter(x, x, markersize=x) From c46095bbd9da5bbdb8d3a24a1814274d05a8d02e Mon Sep 17 00:00:00 2001 From: Chahak Mehta Date: Wed, 15 Mar 2023 18:42:21 -0500 Subject: [PATCH 05/10] Remove errant print --- lib/matplotlib/collections.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index a0ff26fd6daa..534b407160d3 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -981,8 +981,6 @@ def set_sizes(self, sizes, dpi=72.0, markerscale=2): markerscale : 1 or 2, default: 2 Scaling factor used to set the size as points (1) or points**2 (2). """ - # breakpoint() - print(markerscale) self._markerscale = markerscale if sizes is None: self._sizes = np.array([]) From dabe428778d8f661732755da492f5d89c5380b1e Mon Sep 17 00:00:00 2001 From: Chahak Mehta Date: Wed, 26 Apr 2023 22:05:13 -0500 Subject: [PATCH 06/10] Add what's new entry --- doc/users/next_whats_new/scatter_markersize.rst | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 doc/users/next_whats_new/scatter_markersize.rst diff --git a/doc/users/next_whats_new/scatter_markersize.rst b/doc/users/next_whats_new/scatter_markersize.rst new file mode 100644 index 000000000000..edc9eb5ce5ff --- /dev/null +++ b/doc/users/next_whats_new/scatter_markersize.rst @@ -0,0 +1,5 @@ +`markersize` and `markerscale` added to scatter +----------------------------------------------- +`markersize` is new alias for `s` in scatter that can be used to set the size of +the markers. The marker sizes can now also be set using a linear scale using the +`markerscale` parameter. From 2c95f38f0a4e3d35b3a3802209745836cb6a36c1 Mon Sep 17 00:00:00 2001 From: Chahak Mehta Date: Wed, 26 Apr 2023 23:17:41 -0500 Subject: [PATCH 07/10] Add markerscale instead of markersize to pyplot --- lib/matplotlib/pyplot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index a2e8e45781fe..90fc5aa95735 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -3587,8 +3587,8 @@ def scatter( *, edgecolors: Literal["face", "none"] | ColorType | Sequence[ColorType] | None = None, plotnonfinite: bool = False, + markerscale=2, data=None, - markersize: int | None = None, **kwargs, ) -> PathCollection: __ret = gca().scatter( @@ -3605,7 +3605,7 @@ def scatter( linewidths=linewidths, edgecolors=edgecolors, plotnonfinite=plotnonfinite, - markersize=markersize, + markerscale=markerscale, **({"data": data} if data is not None else {}), **kwargs, ) From 75c0084ff872e31211f3b2412e9771293c22a959 Mon Sep 17 00:00:00 2001 From: Chahak Mehta Date: Mon, 8 May 2023 17:22:29 -0500 Subject: [PATCH 08/10] Add stubs and update what's new entry link --- doc/users/next_whats_new/scatter_markersize.rst | 8 ++++---- lib/matplotlib/axes/_axes.pyi | 1 + lib/matplotlib/collections.pyi | 11 +++++++++-- lib/matplotlib/pyplot.py | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/doc/users/next_whats_new/scatter_markersize.rst b/doc/users/next_whats_new/scatter_markersize.rst index edc9eb5ce5ff..d1d1a4165a3e 100644 --- a/doc/users/next_whats_new/scatter_markersize.rst +++ b/doc/users/next_whats_new/scatter_markersize.rst @@ -1,5 +1,5 @@ -`markersize` and `markerscale` added to scatter ------------------------------------------------ -`markersize` is new alias for `s` in scatter that can be used to set the size of +``markersize`` and ``markerscale`` added to scatter +--------------------------------------------------- +``markersize`` is new alias for ``s`` in scatter that can be used to set the size of the markers. The marker sizes can now also be set using a linear scale using the -`markerscale` parameter. +``markerscale`` parameter. diff --git a/lib/matplotlib/axes/_axes.pyi b/lib/matplotlib/axes/_axes.pyi index 4be2c5536105..4bd38238ecb5 100644 --- a/lib/matplotlib/axes/_axes.pyi +++ b/lib/matplotlib/axes/_axes.pyi @@ -411,6 +411,7 @@ class Axes(_AxesBase): *, edgecolors: Literal["face", "none"] | ColorType | Sequence[ColorType] | None = ..., plotnonfinite: bool = ..., + markerscale: int = ..., data=..., **kwargs ) -> PathCollection: ... diff --git a/lib/matplotlib/collections.pyi b/lib/matplotlib/collections.pyi index d276fb8cd2c2..21135773a82b 100644 --- a/lib/matplotlib/collections.pyi +++ b/lib/matplotlib/collections.pyi @@ -70,11 +70,18 @@ class Collection(artist.Artist, cm.ScalarMappable): class _CollectionWithSizes(Collection): def get_sizes(self) -> np.ndarray: ... - def set_sizes(self, sizes: ArrayLike | None, dpi: float = ...) -> None: ... + def set_sizes( + self, sizes: ArrayLike | None, dpi: float = ..., markerscale: int = ... + ) -> None: ... + def get_markerscale(self) -> int: ... class PathCollection(_CollectionWithSizes): def __init__( - self, paths: Sequence[Path], sizes: ArrayLike | None = ..., **kwargs + self, + paths: Sequence[Path], + sizes: ArrayLike | None = ..., + markerscale: int = ..., + **kwargs ) -> None: ... def set_paths(self, paths: Sequence[Path]) -> None: ... def get_paths(self) -> Sequence[Path]: ... diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 90fc5aa95735..af3cb0750bed 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -3587,7 +3587,7 @@ def scatter( *, edgecolors: Literal["face", "none"] | ColorType | Sequence[ColorType] | None = None, plotnonfinite: bool = False, - markerscale=2, + markerscale: int = 2, data=None, **kwargs, ) -> PathCollection: From 1b0a4f478b10b353ea1c0571c10f77bb24cf1d8f Mon Sep 17 00:00:00 2001 From: Chahak Mehta Date: Tue, 9 May 2023 18:57:49 -0500 Subject: [PATCH 09/10] Add versionadded --- lib/matplotlib/axes/_axes.py | 2 ++ lib/matplotlib/collections.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 905d7fb3456c..8d521619be2b 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -4572,6 +4572,8 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, Scaling factor used to set the size as points or points**2. Default value is set as 2 to set the size values as points**2. + .. versionadded:: 3.9 + Returns ------- `~matplotlib.collections.PathCollection` diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 534b407160d3..1ee6b9f70194 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -960,6 +960,8 @@ def get_markerscale(self): """ Return the scale used for marker sizing. + .. versionadded:: 3.9 + Returns ------- int @@ -980,6 +982,8 @@ def set_sizes(self, sizes, dpi=72.0, markerscale=2): The dpi of the canvas. markerscale : 1 or 2, default: 2 Scaling factor used to set the size as points (1) or points**2 (2). + + .. versionadded:: 3.9 """ self._markerscale = markerscale if sizes is None: @@ -1018,6 +1022,9 @@ def __init__(self, paths, sizes=None, markerscale=2, **kwargs): points when rendered. markerscale : 1 or 2, default: 2 Scaling factor used to set the size as points (1) or points**2 (2). + + .. versionadded:: 3.9 + **kwargs Forwarded to `.Collection`. """ From 3cfecf9430152864641a426f58732403d01a700b Mon Sep 17 00:00:00 2001 From: Chahak Mehta Date: Thu, 11 May 2023 16:41:36 -0500 Subject: [PATCH 10/10] Add aliases to mypy allowlist --- ci/mypy-stubtest-allowlist.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ci/mypy-stubtest-allowlist.txt b/ci/mypy-stubtest-allowlist.txt index d6419ca0cff4..2c45525d465b 100644 --- a/ci/mypy-stubtest-allowlist.txt +++ b/ci/mypy-stubtest-allowlist.txt @@ -105,6 +105,10 @@ matplotlib.collections.Collection.set_linewidths matplotlib.collections.Collection.set_ls matplotlib.collections.Collection.set_lw matplotlib.collections.Collection.set_transOffset +matplotlib.collections._CollectionWithSizes.get_markersize +matplotlib.collections._CollectionWithSizes.get_s +matplotlib.collections._CollectionWithSizes.set_markersize +matplotlib.collections._CollectionWithSizes.set_s matplotlib.lines.Line2D.get_aa matplotlib.lines.Line2D.get_c matplotlib.lines.Line2D.get_ds