From 2425bdc91e808cc60e767420675e2155df34ef13 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Thu, 10 Nov 2022 20:23:12 +0100 Subject: [PATCH 01/19] Prioritize mpl kwargs when hue/size isn't defined. --- xarray/plot/dataarray_plot.py | 54 +++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/xarray/plot/dataarray_plot.py b/xarray/plot/dataarray_plot.py index ac23f7dc96d..16dafa36f89 100644 --- a/xarray/plot/dataarray_plot.py +++ b/xarray/plot/dataarray_plot.py @@ -151,7 +151,10 @@ def _infer_line_data( def _infer_plot_dims( darray: DataArray, dims_plot: MutableMapping[str, Hashable], - default_guess: Iterable[str] = ("x", "hue", "size"), + kwargs: dict, + default_guess: tuple[str, ...] = ("x", "hue", "size"), + # TODO: Can this be normalized, plt.cbook.normalize_kwargs? + ignore_guess_kwargs: tuple[tuple[str, ...], ...] = ((), ("c", "color"), ("s")), ) -> MutableMapping[str, Hashable]: """ Guess what dims to plot if some of the values in dims_plot are None which @@ -167,17 +170,49 @@ def _infer_plot_dims( default_guess : Iterable[str], optional Default values and order to retrieve dims if values in dims_plot is missing, default: ("x", "hue", "size"). + + Examples + -------- + >>> ds = xr.tutorial.scatter_example_dataset(seed=42) + >>> # Guess all plot dims: + >>> xr.plot.dataarray_plot._infer_plot_dims( + ... ds.A, + ... dims_plot={"x": None, "z": None, "hue": None, "size": None}, + ... kwargs={}, + ... ) + {'x': 'x', 'z': None, 'hue': 'y', 'size': 'z'} + + >>> # Don't guess ´size´, since the matplotlib kwarg ´s´ has been defined: + >>> xr.plot.dataarray_plot._infer_plot_dims( + ... ds.A, + ... dims_plot={"x": None, "z": None, "hue": None, "size": None}, + ... kwargs={"s": 5}, + ... ) + {'x': 'x', 'z': None, 'hue': 'y', 'size': None} + + >>> # Prioritize ´size´ over ´s´: + >>> xr.plot.dataarray_plot._infer_plot_dims( + ... ds.A, + ... dims_plot={"x": None, "z": None, "hue": None, "size": "x"}, + ... kwargs={"s": 5}, + ... ) + {'x': 'y', 'z': None, 'hue': 'z', 'size': 'x'} """ dims_plot_exist = {k: v for k, v in dims_plot.items() if v is not None} dims_avail = tuple(v for v in darray.dims if v not in dims_plot_exist.values()) - # If dims_plot[k] isn't defined then fill with one of the available dims: - for k, v in zip(default_guess, dims_avail): - if dims_plot.get(k, None) is None: - dims_plot[k] = v + # If dims_plot[k] isn't defined then fill with one of the available dims, unless + # one of related mpl kwargs has been used. This should have similiar behaviour as + # * plt.plot(x, y) -> Multple lines with different colors if y is 2d. + # * plt.plot(x, y, color="red") -> Multiple red lines if y is 2d. + for k, dim, ign in zip(default_guess, dims_avail, ignore_guess_kwargs): + if dims_plot.get(k, None) is None and all( + kwargs.get(k, None) is None for k in ign + ): + dims_plot[k] = dim - for k, v in dims_plot.items(): - _assert_valid_xy(darray, v, k) + for k, dim in dims_plot.items(): + _assert_valid_xy(darray, dim, k) return dims_plot @@ -185,10 +220,11 @@ def _infer_plot_dims( def _infer_line_data2( darray: T_DataArray, dims_plot: MutableMapping[str, Hashable], + kwargs: dict, plotfunc_name: None | str = None, ) -> dict[str, T_DataArray]: # Guess what dims to use if some of the values in plot_dims are None: - dims_plot = _infer_plot_dims(darray, dims_plot) + dims_plot = _infer_plot_dims(darray, dims_plot, kwargs) # If there are more than 1 dimension in the array than stack all the # dimensions so the plotter can plot anything: @@ -949,7 +985,7 @@ def newplotfunc( # Get data to plot: dims_plot = dict(x=x, z=z, hue=hue, size=size_) - plts = _infer_line_data2(darray, dims_plot, plotfunc.__name__) + plts = _infer_line_data2(darray, dims_plot, kwargs, plotfunc.__name__) xplt = plts.pop("x", None) yplt = plts.pop("y", None) zplt = plts.pop("z", None) From 09fedc665c91c3d313bd7494eeabb94241c7d5a9 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Thu, 10 Nov 2022 20:36:37 +0100 Subject: [PATCH 02/19] Update dataarray_plot.py --- xarray/plot/dataarray_plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/plot/dataarray_plot.py b/xarray/plot/dataarray_plot.py index 16dafa36f89..0b3b6674719 100644 --- a/xarray/plot/dataarray_plot.py +++ b/xarray/plot/dataarray_plot.py @@ -154,7 +154,7 @@ def _infer_plot_dims( kwargs: dict, default_guess: tuple[str, ...] = ("x", "hue", "size"), # TODO: Can this be normalized, plt.cbook.normalize_kwargs? - ignore_guess_kwargs: tuple[tuple[str, ...], ...] = ((), ("c", "color"), ("s")), + ignore_guess_kwargs: tuple[tuple[str, ...], ...] = ((), ("c", "color"), ("s",)), ) -> MutableMapping[str, Hashable]: """ Guess what dims to plot if some of the values in dims_plot are None which From a2740e087e754f5c26ec50f16e5877aedaf517e5 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sat, 12 Nov 2022 10:36:22 +0100 Subject: [PATCH 03/19] rename vars for clarity --- xarray/plot/dataarray_plot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/plot/dataarray_plot.py b/xarray/plot/dataarray_plot.py index 0b3b6674719..41b117944da 100644 --- a/xarray/plot/dataarray_plot.py +++ b/xarray/plot/dataarray_plot.py @@ -205,9 +205,9 @@ def _infer_plot_dims( # one of related mpl kwargs has been used. This should have similiar behaviour as # * plt.plot(x, y) -> Multple lines with different colors if y is 2d. # * plt.plot(x, y, color="red") -> Multiple red lines if y is 2d. - for k, dim, ign in zip(default_guess, dims_avail, ignore_guess_kwargs): + for k, dim, ign_kws in zip(default_guess, dims_avail, ignore_guess_kwargs): if dims_plot.get(k, None) is None and all( - kwargs.get(k, None) is None for k in ign + kwargs.get(ign_kw, None) is None for ign_kw in ign_kws ): dims_plot[k] = dim From 4bce4a91e7c1ae904652e6d091f832dccf0d701e Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sun, 13 Nov 2022 18:01:49 +0100 Subject: [PATCH 04/19] Handle int coords --- xarray/plot/dataarray_plot.py | 110 ++++++++++++++++++++++++---------- 1 file changed, 80 insertions(+), 30 deletions(-) diff --git a/xarray/plot/dataarray_plot.py b/xarray/plot/dataarray_plot.py index 41b117944da..1f154148c25 100644 --- a/xarray/plot/dataarray_plot.py +++ b/xarray/plot/dataarray_plot.py @@ -148,83 +148,125 @@ def _infer_line_data( return xplt, yplt, hueplt, huelabel -def _infer_plot_dims( +def _guess_coords_to_plot( darray: DataArray, - dims_plot: MutableMapping[str, Hashable], + coords_to_plot: MutableMapping[str, Hashable], kwargs: dict, default_guess: tuple[str, ...] = ("x", "hue", "size"), # TODO: Can this be normalized, plt.cbook.normalize_kwargs? ignore_guess_kwargs: tuple[tuple[str, ...], ...] = ((), ("c", "color"), ("s",)), ) -> MutableMapping[str, Hashable]: """ - Guess what dims to plot if some of the values in dims_plot are None which + Guess what coords to plot if some of the values in coords_to_plot are None which happens when the user has not defined all available ways of visualizing the data. Parameters ---------- darray : DataArray - The DataArray to check. - dims_plot : T_DimsPlot - Dims defined by the user to plot. + The DataArray to check for available coords. + coords_to_plot : MutableMapping[str, Hashable] + Coords defined by the user to plot. + kwargs : dict + Extra kwargs that will be sent to matplotlib. default_guess : Iterable[str], optional Default values and order to retrieve dims if values in dims_plot is missing, default: ("x", "hue", "size"). + ignore_guess_kwargs : tuple[tuple[str, ...], ...] + Matplotlib arguments to ignore. Examples -------- >>> ds = xr.tutorial.scatter_example_dataset(seed=42) >>> # Guess all plot dims: - >>> xr.plot.dataarray_plot._infer_plot_dims( + >>> xr.plot.dataarray_plot._guess_coords_to_plot( ... ds.A, - ... dims_plot={"x": None, "z": None, "hue": None, "size": None}, + ... coords_to_plot={"x": None, "z": None, "hue": None, "size": None}, ... kwargs={}, ... ) {'x': 'x', 'z': None, 'hue': 'y', 'size': 'z'} >>> # Don't guess ´size´, since the matplotlib kwarg ´s´ has been defined: - >>> xr.plot.dataarray_plot._infer_plot_dims( + >>> xr.plot.dataarray_plot._guess_coords_to_plot( ... ds.A, - ... dims_plot={"x": None, "z": None, "hue": None, "size": None}, + ... coords_to_plot={"x": None, "z": None, "hue": None, "size": None}, ... kwargs={"s": 5}, ... ) {'x': 'x', 'z': None, 'hue': 'y', 'size': None} >>> # Prioritize ´size´ over ´s´: - >>> xr.plot.dataarray_plot._infer_plot_dims( + >>> xr.plot.dataarray_plot._guess_coords_to_plot( ... ds.A, - ... dims_plot={"x": None, "z": None, "hue": None, "size": "x"}, + ... coords_to_plot={"x": None, "z": None, "hue": None, "size": "x"}, ... kwargs={"s": 5}, ... ) {'x': 'y', 'z': None, 'hue': 'z', 'size': 'x'} """ - dims_plot_exist = {k: v for k, v in dims_plot.items() if v is not None} - dims_avail = tuple(v for v in darray.dims if v not in dims_plot_exist.values()) + coords_to_plot_exist = {k: v for k, v in coords_to_plot.items() if v is not None} + available_coords = tuple( + k for k in darray.coords.keys() if k not in coords_to_plot_exist.values() + ) # If dims_plot[k] isn't defined then fill with one of the available dims, unless # one of related mpl kwargs has been used. This should have similiar behaviour as # * plt.plot(x, y) -> Multple lines with different colors if y is 2d. # * plt.plot(x, y, color="red") -> Multiple red lines if y is 2d. - for k, dim, ign_kws in zip(default_guess, dims_avail, ignore_guess_kwargs): - if dims_plot.get(k, None) is None and all( + for k, dim, ign_kws in zip(default_guess, available_coords, ignore_guess_kwargs): + if coords_to_plot.get(k, None) is None and all( kwargs.get(ign_kw, None) is None for ign_kw in ign_kws ): - dims_plot[k] = dim + coords_to_plot[k] = dim - for k, dim in dims_plot.items(): + for k, dim in coords_to_plot.items(): _assert_valid_xy(darray, dim, k) - return dims_plot + return coords_to_plot def _infer_line_data2( darray: T_DataArray, - dims_plot: MutableMapping[str, Hashable], + coords_to_plot: MutableMapping[str, Hashable], kwargs: dict, - plotfunc_name: None | str = None, + plotfunc_name: str | None = None, + _is_facetgrid: bool = False, ) -> dict[str, T_DataArray]: + """ + Infer data to plot. If no + + Parameters + ---------- + darray : T_DataArray + Base DataArray. + coords_to_plot : MutableMapping[str, Hashable] + Coords defined by the user to plot. + kwargs : dict + Extra kwargs that will be sent to matplotlib. + plotfunc_name : str | None + Name of the plotting function that will be used. + + Returns + ------- + plts : dict[str, T_DataArray] + Dict of DataArrays that will be sent to matplotlib. + + Examples + -------- + >>> # Make sure int coords are plotted: + >>> a = xr.DataArray( + ... data=[1, 2], coords={1: ("x", [0, 1], {"units": "s"})}, dims=("x",), name="a" + ... ) + >>> plts = xr.plot.dataarray_plot._infer_line_data2( + ... a, + ... coords_to_plot={"x": None, "z": None, "hue": None, "size": None}, + ... kwargs={}, + ... ) + >>> # Check which coords to plot: + >>> print({k: v.name for k, v in plts.items()}) + {'y': 'a', 'x': 1} + """ # Guess what dims to use if some of the values in plot_dims are None: - dims_plot = _infer_plot_dims(darray, dims_plot, kwargs) + if _is_facetgrid: + coords_to_plot = _guess_coords_to_plot(darray, coords_to_plot, kwargs) # If there are more than 1 dimension in the array than stack all the # dimensions so the plotter can plot anything: @@ -235,11 +277,11 @@ def _infer_line_data2( dims_T = [] if np.issubdtype(darray.dtype, np.floating): for v in ["z", "x"]: - dim = dims_plot.get(v, None) + dim = coords_to_plot.get(v, None) if (dim is not None) and (dim in darray.dims): darray_nan = np.nan * darray.isel({dim: -1}) darray = concat([darray, darray_nan], dim=dim) - dims_T.append(dims_plot[v]) + dims_T.append(coords_to_plot[v]) # Lines should never connect to the same coordinate when stacked, # transpose to avoid this as much as possible: @@ -249,11 +291,13 @@ def _infer_line_data2( darray = darray.stack(_stacked_dim=darray.dims) # Broadcast together all the chosen variables: - out = dict(y=darray) - out.update({k: darray[v] for k, v in dims_plot.items() if v is not None}) - out = dict(zip(out.keys(), broadcast(*(out.values())))) + plts = dict(y=darray) + plts.update( + {k: darray.coords[v] for k, v in coords_to_plot.items() if v is not None} + ) + plts = dict(zip(plts.keys(), broadcast(*(plts.values())))) - return out + return plts # return type is Any due to the many different possibilities @@ -984,8 +1028,14 @@ def newplotfunc( size_r = _LINEWIDTH_RANGE # Get data to plot: - dims_plot = dict(x=x, z=z, hue=hue, size=size_) - plts = _infer_line_data2(darray, dims_plot, kwargs, plotfunc.__name__) + coords_to_plot = dict(x=x, z=z, hue=hue, size=size_) + plts = _infer_line_data2( + darray, + coords_to_plot, + kwargs, + plotfunc.__name__, + _is_facetgrid=_is_facetgrid, + ) xplt = plts.pop("x", None) yplt = plts.pop("y", None) zplt = plts.pop("z", None) From b885289222818a4b34f503497d6be5da8474f61e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 13 Nov 2022 17:03:17 +0000 Subject: [PATCH 05/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/plot/dataarray_plot.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xarray/plot/dataarray_plot.py b/xarray/plot/dataarray_plot.py index 1f154148c25..0dd6b314f40 100644 --- a/xarray/plot/dataarray_plot.py +++ b/xarray/plot/dataarray_plot.py @@ -253,7 +253,10 @@ def _infer_line_data2( -------- >>> # Make sure int coords are plotted: >>> a = xr.DataArray( - ... data=[1, 2], coords={1: ("x", [0, 1], {"units": "s"})}, dims=("x",), name="a" + ... data=[1, 2], + ... coords={1: ("x", [0, 1], {"units": "s"})}, + ... dims=("x",), + ... name="a", ... ) >>> plts = xr.plot.dataarray_plot._infer_line_data2( ... a, From 192fd47b4b7c749f1fd2fe191008b47cae826a68 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sun, 13 Nov 2022 18:09:18 +0100 Subject: [PATCH 06/19] Update dataarray_plot.py --- xarray/plot/dataarray_plot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/plot/dataarray_plot.py b/xarray/plot/dataarray_plot.py index 1f154148c25..0337f680f80 100644 --- a/xarray/plot/dataarray_plot.py +++ b/xarray/plot/dataarray_plot.py @@ -231,7 +231,7 @@ def _infer_line_data2( _is_facetgrid: bool = False, ) -> dict[str, T_DataArray]: """ - Infer data to plot. If no + Infer data to plot. Parameters ---------- @@ -265,7 +265,7 @@ def _infer_line_data2( {'y': 'a', 'x': 1} """ # Guess what dims to use if some of the values in plot_dims are None: - if _is_facetgrid: + if not _is_facetgrid: coords_to_plot = _guess_coords_to_plot(darray, coords_to_plot, kwargs) # If there are more than 1 dimension in the array than stack all the From b534f9a08a527708f6ab72b64005d0fdf8524ea6 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sun, 13 Nov 2022 23:13:47 +0100 Subject: [PATCH 07/19] Move funcs to utils and use in facetgrid, fix int coords in facetgrid --- xarray/plot/dataarray_plot.py | 103 +++------------------------------- xarray/plot/facetgrid.py | 39 ++++++++----- xarray/plot/utils.py | 76 +++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 107 deletions(-) diff --git a/xarray/plot/dataarray_plot.py b/xarray/plot/dataarray_plot.py index b94cd1eecde..bb6813d298d 100644 --- a/xarray/plot/dataarray_plot.py +++ b/xarray/plot/dataarray_plot.py @@ -29,6 +29,7 @@ _assert_valid_xy, _determine_guide, _ensure_plottable, + _guess_coords_to_plot, _infer_interval_breaks, _infer_xy_labels, _Normalize, @@ -148,85 +149,9 @@ def _infer_line_data( return xplt, yplt, hueplt, huelabel -def _guess_coords_to_plot( - darray: DataArray, - coords_to_plot: MutableMapping[str, Hashable], - kwargs: dict, - default_guess: tuple[str, ...] = ("x", "hue", "size"), - # TODO: Can this be normalized, plt.cbook.normalize_kwargs? - ignore_guess_kwargs: tuple[tuple[str, ...], ...] = ((), ("c", "color"), ("s",)), -) -> MutableMapping[str, Hashable]: - """ - Guess what coords to plot if some of the values in coords_to_plot are None which - happens when the user has not defined all available ways of visualizing - the data. - - Parameters - ---------- - darray : DataArray - The DataArray to check for available coords. - coords_to_plot : MutableMapping[str, Hashable] - Coords defined by the user to plot. - kwargs : dict - Extra kwargs that will be sent to matplotlib. - default_guess : Iterable[str], optional - Default values and order to retrieve dims if values in dims_plot is - missing, default: ("x", "hue", "size"). - ignore_guess_kwargs : tuple[tuple[str, ...], ...] - Matplotlib arguments to ignore. - - Examples - -------- - >>> ds = xr.tutorial.scatter_example_dataset(seed=42) - >>> # Guess all plot dims: - >>> xr.plot.dataarray_plot._guess_coords_to_plot( - ... ds.A, - ... coords_to_plot={"x": None, "z": None, "hue": None, "size": None}, - ... kwargs={}, - ... ) - {'x': 'x', 'z': None, 'hue': 'y', 'size': 'z'} - - >>> # Don't guess ´size´, since the matplotlib kwarg ´s´ has been defined: - >>> xr.plot.dataarray_plot._guess_coords_to_plot( - ... ds.A, - ... coords_to_plot={"x": None, "z": None, "hue": None, "size": None}, - ... kwargs={"s": 5}, - ... ) - {'x': 'x', 'z': None, 'hue': 'y', 'size': None} - - >>> # Prioritize ´size´ over ´s´: - >>> xr.plot.dataarray_plot._guess_coords_to_plot( - ... ds.A, - ... coords_to_plot={"x": None, "z": None, "hue": None, "size": "x"}, - ... kwargs={"s": 5}, - ... ) - {'x': 'y', 'z': None, 'hue': 'z', 'size': 'x'} - """ - coords_to_plot_exist = {k: v for k, v in coords_to_plot.items() if v is not None} - available_coords = tuple( - k for k in darray.coords.keys() if k not in coords_to_plot_exist.values() - ) - - # If dims_plot[k] isn't defined then fill with one of the available dims, unless - # one of related mpl kwargs has been used. This should have similiar behaviour as - # * plt.plot(x, y) -> Multple lines with different colors if y is 2d. - # * plt.plot(x, y, color="red") -> Multiple red lines if y is 2d. - for k, dim, ign_kws in zip(default_guess, available_coords, ignore_guess_kwargs): - if coords_to_plot.get(k, None) is None and all( - kwargs.get(ign_kw, None) is None for ign_kw in ign_kws - ): - coords_to_plot[k] = dim - - for k, dim in coords_to_plot.items(): - _assert_valid_xy(darray, dim, k) - - return coords_to_plot - - def _infer_line_data2( darray: T_DataArray, coords_to_plot: MutableMapping[str, Hashable], - kwargs: dict, plotfunc_name: str | None = None, _is_facetgrid: bool = False, ) -> dict[str, T_DataArray]: @@ -238,9 +163,7 @@ def _infer_line_data2( darray : T_DataArray Base DataArray. coords_to_plot : MutableMapping[str, Hashable] - Coords defined by the user to plot. - kwargs : dict - Extra kwargs that will be sent to matplotlib. + Coords that will be plotted. plotfunc_name : str | None Name of the plotting function that will be used. @@ -260,17 +183,12 @@ def _infer_line_data2( ... ) >>> plts = xr.plot.dataarray_plot._infer_line_data2( ... a, - ... coords_to_plot={"x": None, "z": None, "hue": None, "size": None}, - ... kwargs={}, + ... coords_to_plot={"x": 1, "z": None, "hue": None, "size": None} ... ) >>> # Check which coords to plot: >>> print({k: v.name for k, v in plts.items()}) {'y': 'a', 'x': 1} """ - # Guess what dims to use if some of the values in plot_dims are None: - if not _is_facetgrid: - coords_to_plot = _guess_coords_to_plot(darray, coords_to_plot, kwargs) - # If there are more than 1 dimension in the array than stack all the # dimensions so the plotter can plot anything: if darray.ndim > 1: @@ -1024,21 +942,18 @@ def newplotfunc( _is_facetgrid = kwargs.pop("_is_facetgrid", False) if plotfunc.__name__ == "scatter": - size_ = markersize + size_ = kwargs.pop("_size", markersize) size_r = _MARKERSIZE_RANGE else: - size_ = linewidth + size_ = kwargs.pop("_size", linewidth) size_r = _LINEWIDTH_RANGE # Get data to plot: coords_to_plot = dict(x=x, z=z, hue=hue, size=size_) - plts = _infer_line_data2( - darray, - coords_to_plot, - kwargs, - plotfunc.__name__, - _is_facetgrid=_is_facetgrid, - ) + if not _is_facetgrid: + # Guess what coords to use if some of the values in coords_to_plot are None: + coords_to_plot = _guess_coords_to_plot(darray, coords_to_plot, kwargs) + plts = _infer_line_data2(darray, coords_to_plot, plotfunc.__name__) xplt = plts.pop("x", None) yplt = plts.pop("y", None) zplt = plts.pop("z", None) diff --git a/xarray/plot/facetgrid.py b/xarray/plot/facetgrid.py index 91b0deba454..782de1dc2ec 100644 --- a/xarray/plot/facetgrid.py +++ b/xarray/plot/facetgrid.py @@ -25,6 +25,7 @@ _add_legend, _determine_guide, _get_nice_quiver_magnitude, + _guess_coords_to_plot, _infer_xy_labels, _Normalize, _parse_size, @@ -392,6 +393,11 @@ def map_plot1d( func: Callable, x: Hashable | None, y: Hashable | None, + *, + z: Hashable | None = None, + hue: Hashable | None = None, + markersize: Hashable | None = None, + linewidth: Hashable | None = None, **kwargs: Any, ) -> T_FacetGrid: """ @@ -424,13 +430,23 @@ def map_plot1d( if kwargs.get("cbar_ax", None) is not None: raise ValueError("cbar_ax not supported by FacetGrid.") + if func.__name__ == "scatter": + size_ = kwargs.pop("_size", markersize) + size_r = _MARKERSIZE_RANGE + else: + size_ = kwargs.pop("_size", linewidth) + size_r = _LINEWIDTH_RANGE + + # Guess what coords to use if some of the values in coords_to_plot are None: + coords_to_plot = dict(x=x, z=z, hue=hue, size=size_) + coords_to_plot = _guess_coords_to_plot(self.data, coords_to_plot, kwargs) + # Handle hues: - hue = kwargs.get("hue", None) - hueplt = self.data[hue] if hue else self.data + hue = coords_to_plot["hue"] + hueplt = self.data.coords[hue] if hue else None # TODO: _infer_line_data2 ? hueplt_norm = _Normalize(hueplt) self._hue_var = hueplt cbar_kwargs = kwargs.pop("cbar_kwargs", {}) - if hueplt_norm.data is not None: if not hueplt_norm.data_is_numeric: # TODO: Ticks seems a little too hardcoded, since it will always @@ -450,16 +466,11 @@ def map_plot1d( cmap_params = {} # Handle sizes: - _size_r = _MARKERSIZE_RANGE if func.__name__ == "scatter" else _LINEWIDTH_RANGE - for _size in ("markersize", "linewidth"): - size = kwargs.get(_size, None) - - sizeplt = self.data[size] if size else None - sizeplt_norm = _Normalize(data=sizeplt, width=_size_r) - if size: - self.data[size] = sizeplt_norm.values - kwargs.update(**{_size: size}) - break + size_ = coords_to_plot["size"] + sizeplt = self.data.coords[size_] if size_ else None + sizeplt_norm = _Normalize(data=sizeplt, width=size_r) + if sizeplt_norm.data is not None: + self.data[size_] = sizeplt_norm.values # Add kwargs that are sent to the plotting function, # order is important ??? func_kwargs = { @@ -513,6 +524,8 @@ def map_plot1d( x=x, y=y, ax=ax, + hue=hue, + _size=size_, **func_kwargs, _is_facetgrid=True, ) diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index 80339ca8240..f4fe79b35af 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -12,6 +12,7 @@ Hashable, Iterable, Mapping, + MutableMapping, Sequence, overload, ) @@ -1747,3 +1748,78 @@ def _add_legend( _adjust_legend_subtitles(legend) return legend + + +def _guess_coords_to_plot( + darray: DataArray, + coords_to_plot: MutableMapping[str, Hashable], + kwargs: dict, + default_guess: tuple[str, ...] = ("x", "hue", "size"), + # TODO: Can this be normalized, plt.cbook.normalize_kwargs? + ignore_guess_kwargs: tuple[tuple[str, ...], ...] = ((), ("c", "color"), ("s",)), +) -> MutableMapping[str, Hashable]: + """ + Guess what coords to plot if some of the values in coords_to_plot are None which + happens when the user has not defined all available ways of visualizing + the data. + + Parameters + ---------- + darray : DataArray + The DataArray to check for available coords. + coords_to_plot : MutableMapping[str, Hashable] + Coords defined by the user to plot. + kwargs : dict + Extra kwargs that will be sent to matplotlib. + default_guess : Iterable[str], optional + Default values and order to retrieve dims if values in dims_plot is + missing, default: ("x", "hue", "size"). + ignore_guess_kwargs : tuple[tuple[str, ...], ...] + Matplotlib arguments to ignore. + + Examples + -------- + >>> ds = xr.tutorial.scatter_example_dataset(seed=42) + >>> # Guess all plot dims: + >>> xr.plot.dataarray_plot._guess_coords_to_plot( + ... ds.A, + ... coords_to_plot={"x": None, "z": None, "hue": None, "size": None}, + ... kwargs={}, + ... ) + {'x': 'x', 'z': None, 'hue': 'y', 'size': 'z'} + + >>> # Don't guess ´size´, since the matplotlib kwarg ´s´ has been defined: + >>> xr.plot.dataarray_plot._guess_coords_to_plot( + ... ds.A, + ... coords_to_plot={"x": None, "z": None, "hue": None, "size": None}, + ... kwargs={"s": 5}, + ... ) + {'x': 'x', 'z': None, 'hue': 'y', 'size': None} + + >>> # Prioritize ´size´ over ´s´: + >>> xr.plot.dataarray_plot._guess_coords_to_plot( + ... ds.A, + ... coords_to_plot={"x": None, "z": None, "hue": None, "size": "x"}, + ... kwargs={"s": 5}, + ... ) + {'x': 'y', 'z': None, 'hue': 'z', 'size': 'x'} + """ + coords_to_plot_exist = {k: v for k, v in coords_to_plot.items() if v is not None} + available_coords = tuple( + k for k in darray.coords.keys() if k not in coords_to_plot_exist.values() + ) + + # If dims_plot[k] isn't defined then fill with one of the available dims, unless + # one of related mpl kwargs has been used. This should have similiar behaviour as + # * plt.plot(x, y) -> Multple lines with different colors if y is 2d. + # * plt.plot(x, y, color="red") -> Multiple red lines if y is 2d. + for k, dim, ign_kws in zip(default_guess, available_coords, ignore_guess_kwargs): + if coords_to_plot.get(k, None) is None and all( + kwargs.get(ign_kw, None) is None for ign_kw in ign_kws + ): + coords_to_plot[k] = dim + + for k, dim in coords_to_plot.items(): + _assert_valid_xy(darray, dim, k) + + return coords_to_plot From f6d8a679ed283d2a9a6b3180e7bc36df10389c52 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 13 Nov 2022 22:15:07 +0000 Subject: [PATCH 08/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/plot/dataarray_plot.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xarray/plot/dataarray_plot.py b/xarray/plot/dataarray_plot.py index bb6813d298d..210b1b43fee 100644 --- a/xarray/plot/dataarray_plot.py +++ b/xarray/plot/dataarray_plot.py @@ -182,8 +182,7 @@ def _infer_line_data2( ... name="a", ... ) >>> plts = xr.plot.dataarray_plot._infer_line_data2( - ... a, - ... coords_to_plot={"x": 1, "z": None, "hue": None, "size": None} + ... a, coords_to_plot={"x": 1, "z": None, "hue": None, "size": None} ... ) >>> # Check which coords to plot: >>> print({k: v.name for k, v in plts.items()}) From a53c17f0b34d2901053c97af0b8b8e552ff6fe64 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sun, 13 Nov 2022 23:24:23 +0100 Subject: [PATCH 09/19] Update dataarray_plot.py --- xarray/plot/dataarray_plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/plot/dataarray_plot.py b/xarray/plot/dataarray_plot.py index bb6813d298d..79fb154986f 100644 --- a/xarray/plot/dataarray_plot.py +++ b/xarray/plot/dataarray_plot.py @@ -949,7 +949,7 @@ def newplotfunc( size_r = _LINEWIDTH_RANGE # Get data to plot: - coords_to_plot = dict(x=x, z=z, hue=hue, size=size_) + coords_to_plot: dict[str, Hashable | None] = dict(x=x, z=z, hue=hue, size=size_) if not _is_facetgrid: # Guess what coords to use if some of the values in coords_to_plot are None: coords_to_plot = _guess_coords_to_plot(darray, coords_to_plot, kwargs) From 2ee9e475398e3eea774e6094ca82a5cdb0fd492e Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sun, 13 Nov 2022 23:41:58 +0100 Subject: [PATCH 10/19] Update utils.py --- xarray/plot/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index f4fe79b35af..3fa55d1254f 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -1752,7 +1752,7 @@ def _add_legend( def _guess_coords_to_plot( darray: DataArray, - coords_to_plot: MutableMapping[str, Hashable], + coords_to_plot: MutableMapping[str, Hashable | None], kwargs: dict, default_guess: tuple[str, ...] = ("x", "hue", "size"), # TODO: Can this be normalized, plt.cbook.normalize_kwargs? From cf7a01699680d92bf9a0a567dd8c98f179ab6527 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sun, 13 Nov 2022 23:46:21 +0100 Subject: [PATCH 11/19] Update utils.py --- xarray/plot/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index 3fa55d1254f..266dac8f7fb 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -1781,7 +1781,7 @@ def _guess_coords_to_plot( -------- >>> ds = xr.tutorial.scatter_example_dataset(seed=42) >>> # Guess all plot dims: - >>> xr.plot.dataarray_plot._guess_coords_to_plot( + >>> xr.plot.utils._guess_coords_to_plot( ... ds.A, ... coords_to_plot={"x": None, "z": None, "hue": None, "size": None}, ... kwargs={}, @@ -1789,7 +1789,7 @@ def _guess_coords_to_plot( {'x': 'x', 'z': None, 'hue': 'y', 'size': 'z'} >>> # Don't guess ´size´, since the matplotlib kwarg ´s´ has been defined: - >>> xr.plot.dataarray_plot._guess_coords_to_plot( + >>> xr.plot.utils._guess_coords_to_plot( ... ds.A, ... coords_to_plot={"x": None, "z": None, "hue": None, "size": None}, ... kwargs={"s": 5}, @@ -1797,7 +1797,7 @@ def _guess_coords_to_plot( {'x': 'x', 'z': None, 'hue': 'y', 'size': None} >>> # Prioritize ´size´ over ´s´: - >>> xr.plot.dataarray_plot._guess_coords_to_plot( + >>> xr.plot.utils._guess_coords_to_plot( ... ds.A, ... coords_to_plot={"x": None, "z": None, "hue": None, "size": "x"}, ... kwargs={"s": 5}, From c4a0c48ee7482bfe74a10583adfeba1dc59fb297 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sun, 13 Nov 2022 23:53:33 +0100 Subject: [PATCH 12/19] Update facetgrid.py --- xarray/plot/facetgrid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/plot/facetgrid.py b/xarray/plot/facetgrid.py index 782de1dc2ec..b178bc63c1e 100644 --- a/xarray/plot/facetgrid.py +++ b/xarray/plot/facetgrid.py @@ -438,7 +438,7 @@ def map_plot1d( size_r = _LINEWIDTH_RANGE # Guess what coords to use if some of the values in coords_to_plot are None: - coords_to_plot = dict(x=x, z=z, hue=hue, size=size_) + coords_to_plot: dict[str, Hashable | None] = dict(x=x, z=z, hue=hue, size=size_) coords_to_plot = _guess_coords_to_plot(self.data, coords_to_plot, kwargs) # Handle hues: From a5e6842ae2d9dd44795dd949719b1a3a30be1661 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Wed, 23 Nov 2022 06:45:29 +0100 Subject: [PATCH 13/19] typing fixes --- xarray/plot/dataarray_plot.py | 4 +++- xarray/plot/facetgrid.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/xarray/plot/dataarray_plot.py b/xarray/plot/dataarray_plot.py index 73c99f47b1d..53159e325bf 100644 --- a/xarray/plot/dataarray_plot.py +++ b/xarray/plot/dataarray_plot.py @@ -948,7 +948,9 @@ def newplotfunc( size_r = _LINEWIDTH_RANGE # Get data to plot: - coords_to_plot: dict[str, Hashable | None] = dict(x=x, z=z, hue=hue, size=size_) + coords_to_plot: MutableMapping[str, Hashable | None] = dict( + x=x, z=z, hue=hue, size=size_ + ) if not _is_facetgrid: # Guess what coords to use if some of the values in coords_to_plot are None: coords_to_plot = _guess_coords_to_plot(darray, coords_to_plot, kwargs) diff --git a/xarray/plot/facetgrid.py b/xarray/plot/facetgrid.py index b178bc63c1e..748686eb00b 100644 --- a/xarray/plot/facetgrid.py +++ b/xarray/plot/facetgrid.py @@ -11,6 +11,7 @@ Hashable, Iterable, Literal, + MutableMapping, TypeVar, cast, ) @@ -438,7 +439,9 @@ def map_plot1d( size_r = _LINEWIDTH_RANGE # Guess what coords to use if some of the values in coords_to_plot are None: - coords_to_plot: dict[str, Hashable | None] = dict(x=x, z=z, hue=hue, size=size_) + coords_to_plot: MutableMapping[str, Hashable | None] = dict( + x=x, z=z, hue=hue, size=size_ + ) coords_to_plot = _guess_coords_to_plot(self.data, coords_to_plot, kwargs) # Handle hues: From 58944ebcc5fbaaed33bbb631a85cafa40473b75d Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Wed, 23 Nov 2022 19:11:47 +0100 Subject: [PATCH 14/19] Only guess x-axis. --- xarray/plot/utils.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index 1fe3320214a..3d815bb6256 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -1756,9 +1756,9 @@ def _guess_coords_to_plot( darray: DataArray, coords_to_plot: MutableMapping[str, Hashable | None], kwargs: dict, - default_guess: tuple[str, ...] = ("x", "hue", "size"), + default_guess: tuple[str, ...] = ("x",), # TODO: Can this be normalized, plt.cbook.normalize_kwargs? - ignore_guess_kwargs: tuple[tuple[str, ...], ...] = ((), ("c", "color"), ("s",)), + ignore_guess_kwargs: tuple[tuple[str, ...], ...] = ((),), ) -> MutableMapping[str, Hashable]: """ Guess what coords to plot if some of the values in coords_to_plot are None which @@ -1782,12 +1782,22 @@ def _guess_coords_to_plot( Examples -------- >>> ds = xr.tutorial.scatter_example_dataset(seed=42) - >>> # Guess all plot dims: + >>> # Only guess x by default: >>> xr.plot.utils._guess_coords_to_plot( ... ds.A, ... coords_to_plot={"x": None, "z": None, "hue": None, "size": None}, ... kwargs={}, ... ) + {'x': 'x', 'z': None, 'hue': None, 'size': None} + + >>> # Guess all plot dims with other default values: + >>> xr.plot.utils._guess_coords_to_plot( + ... ds.A, + ... coords_to_plot={"x": None, "z": None, "hue": None, "size": None}, + ... kwargs={}, + ... default_guess=("x", "hue", "size"), + ... ignore_guess_kwargs=((), ("c", "color"), ("s",)), + ... ) {'x': 'x', 'z': None, 'hue': 'y', 'size': 'z'} >>> # Don't guess ´size´, since the matplotlib kwarg ´s´ has been defined: @@ -1795,6 +1805,8 @@ def _guess_coords_to_plot( ... ds.A, ... coords_to_plot={"x": None, "z": None, "hue": None, "size": None}, ... kwargs={"s": 5}, + ... default_guess=("x", "hue", "size"), + ... ignore_guess_kwargs=((), ("c", "color"), ("s",)), ... ) {'x': 'x', 'z': None, 'hue': 'y', 'size': None} @@ -1803,6 +1815,8 @@ def _guess_coords_to_plot( ... ds.A, ... coords_to_plot={"x": None, "z": None, "hue": None, "size": "x"}, ... kwargs={"s": 5}, + ... default_guess=("x", "hue", "size"), + ... ignore_guess_kwargs=((), ("c", "color"), ("s",)), ... ) {'x': 'y', 'z': None, 'hue': 'z', 'size': 'x'} """ From 04694f934fc9c4c7ae98efc6c24698dedf9ad9c4 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Wed, 23 Nov 2022 19:45:13 +0100 Subject: [PATCH 15/19] fix tests --- xarray/tests/test_plot.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 88f03c03b40..056f781d4e1 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -2730,7 +2730,7 @@ def test_scatter( def test_non_numeric_legend(self) -> None: ds2 = self.ds.copy() ds2["hue"] = ["a", "b", "c", "d"] - pc = ds2.plot.scatter(x="A", y="B", hue="hue") + pc = ds2.plot.scatter(x="A", y="B", markersize="hue") # should make a discrete legend assert pc.axes.legend_ is not None @@ -2738,15 +2738,9 @@ def test_legend_labels(self) -> None: # regression test for #4126: incorrect legend labels ds2 = self.ds.copy() ds2["hue"] = ["a", "a", "b", "b"] - pc = ds2.plot.scatter(x="A", y="B", hue="hue") + pc = ds2.plot.scatter(x="A", y="B", markersize="hue") actual = [t.get_text() for t in pc.axes.get_legend().texts] - expected = [ - "col [colunits]", - "$\\mathdefault{0}$", - "$\\mathdefault{1}$", - "$\\mathdefault{2}$", - "$\\mathdefault{3}$", - ] + expected = ["hue", "a", "b"] assert actual == expected def test_legend_labels_facetgrid(self) -> None: From 681ec7566ef9729a9189d579397a42dbd09c0411 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Thu, 26 Jan 2023 20:13:44 +0100 Subject: [PATCH 16/19] rename function to a better name. --- xarray/plot/dataarray_plot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xarray/plot/dataarray_plot.py b/xarray/plot/dataarray_plot.py index ccf9916cacf..70ae780f47e 100644 --- a/xarray/plot/dataarray_plot.py +++ b/xarray/plot/dataarray_plot.py @@ -149,14 +149,14 @@ def _infer_line_data( return xplt, yplt, hueplt, huelabel -def _infer_line_data2( +def _prepare_plot1d_data( darray: T_DataArray, coords_to_plot: MutableMapping[str, Hashable], plotfunc_name: str | None = None, _is_facetgrid: bool = False, ) -> dict[str, T_DataArray]: """ - Infer data to plot. + Prepare data for usage with plt.scatter. Parameters ---------- @@ -181,7 +181,7 @@ def _infer_line_data2( ... dims=("x",), ... name="a", ... ) - >>> plts = xr.plot.dataarray_plot._infer_line_data2( + >>> plts = xr.plot.dataarray_plot._prepare_plot1d_data( ... a, coords_to_plot={"x": 1, "z": None, "hue": None, "size": None} ... ) >>> # Check which coords to plot: @@ -954,7 +954,7 @@ def newplotfunc( if not _is_facetgrid: # Guess what coords to use if some of the values in coords_to_plot are None: coords_to_plot = _guess_coords_to_plot(darray, coords_to_plot, kwargs) - plts = _infer_line_data2(darray, coords_to_plot, plotfunc.__name__) + plts = _prepare_plot1d_data(darray, coords_to_plot, plotfunc.__name__) xplt = plts.pop("x", None) yplt = plts.pop("y", None) zplt = plts.pop("z", None) From db0f64e157b9110a26ac23c34d2347003ba7973b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 26 Jan 2023 19:18:01 +0000 Subject: [PATCH 17/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/plot/facetgrid.py | 2 +- xarray/plot/utils.py | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/xarray/plot/facetgrid.py b/xarray/plot/facetgrid.py index 109a34ae9f7..13d29b0d2f0 100644 --- a/xarray/plot/facetgrid.py +++ b/xarray/plot/facetgrid.py @@ -10,10 +10,10 @@ Callable, Generic, Literal, - MutableMapping, TypeVar, cast, ) +from collections.abc import MutableMapping import numpy as np diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index c67dfe0ac38..bb83ef11c62 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -10,13 +10,9 @@ TYPE_CHECKING, Any, Callable, - Hashable, - Iterable, - Mapping, - MutableMapping, - Sequence, overload, ) +from collections.abc import Hashable, Iterable, Mapping, MutableMapping, Sequence import numpy as np import pandas as pd From 0c140b2df2a03471a89e9e58580f2d36aee3e589 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 26 Jan 2023 20:52:38 +0000 Subject: [PATCH 18/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/plot/facetgrid.py | 13 ++----------- xarray/plot/utils.py | 10 ++-------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/xarray/plot/facetgrid.py b/xarray/plot/facetgrid.py index 13d29b0d2f0..93a328836d0 100644 --- a/xarray/plot/facetgrid.py +++ b/xarray/plot/facetgrid.py @@ -3,17 +3,8 @@ import functools import itertools import warnings -from collections.abc import Hashable, Iterable -from typing import ( - TYPE_CHECKING, - Any, - Callable, - Generic, - Literal, - TypeVar, - cast, -) -from collections.abc import MutableMapping +from collections.abc import Hashable, Iterable, MutableMapping +from typing import TYPE_CHECKING, Any, Callable, Generic, Literal, TypeVar, cast import numpy as np diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index bb83ef11c62..b8eb22b427a 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -3,16 +3,10 @@ import itertools import textwrap import warnings -from collections.abc import Hashable, Iterable, Mapping, Sequence +from collections.abc import Hashable, Iterable, Mapping, MutableMapping, Sequence from datetime import datetime from inspect import getfullargspec -from typing import ( - TYPE_CHECKING, - Any, - Callable, - overload, -) -from collections.abc import Hashable, Iterable, Mapping, MutableMapping, Sequence +from typing import TYPE_CHECKING, Any, Callable, overload import numpy as np import pandas as pd From bcdd8188d52b79f3316b626796b6a31dc0926945 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Thu, 9 Feb 2023 17:53:48 +0100 Subject: [PATCH 19/19] Update whats-new.rst --- doc/whats-new.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index cbb63feda96..3287374d5c3 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -34,7 +34,12 @@ Deprecations Bug fixes ~~~~~~~~~ - +- Require to explicitly defining optional dimensions such as hue + and markersize for scatter plots. (:issue:`7314`, :pull:`7277`). + By `Jimmy Westling `_. +- Fix matplotlib raising a UserWarning when plotting a scatter plot + with an unfilled marker (:issue:`7313`, :pull:`7318`). + By `Jimmy Westling `_. Documentation ~~~~~~~~~~~~~ @@ -194,9 +199,6 @@ Bug fixes By `Michael Niklas `_. - Fix static typing of :py:meth:`xr.polyval` (:issue:`7312`, :pull:`7315`). By `Michael Niklas `_. -- Fix matplotlib raising a UserWarning when plotting a scatter plot - with an unfilled marker (:issue:`7313`, :pull:`7318`). - By `Jimmy Westling `_. - Fix multiple reads on fsspec S3 files by resetting file pointer to 0 when reading file streams (:issue:`6813`, :pull:`7304`). By `David Hoese `_ and `Wei Ji Leong `_. - Fix :py:meth:`Dataset.assign_coords` resetting all dimension coordinates to default (pandas) index (:issue:`7346`, :pull:`7347`).