Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hue_style from plot1d docstring #7925

Merged
merged 13 commits into from
Jul 13, 2023
5 changes: 2 additions & 3 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Breaking changes

Deprecations
~~~~~~~~~~~~

- `hue_style` is being deprecated for scatter plots. (:issue:`7907`, :pull:`7925`).
By `Jimmy Westling <https://github.com/illviljan>`_.

Bug fixes
~~~~~~~~~
Expand All @@ -43,8 +44,6 @@ Internal Changes
~~~~~~~~~~~~~~~~


.. _whats-new.2023.07.0:

v2023.07.0 (July 11, 2023)
--------------------------

Expand Down
22 changes: 13 additions & 9 deletions xarray/plot/dataarray_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,15 +733,6 @@ def _plot1d(plotfunc):
If specified plot 3D and use this coordinate for *z* axis.
hue : Hashable or None, optional
Dimension or coordinate for which you want multiple lines plotted.
hue_style: {'discrete', 'continuous'} or None, optional
How to use the ``hue`` variable:

- ``'continuous'`` -- continuous color scale
(default for numeric ``hue`` variables)
- ``'discrete'`` -- a color for each unique value,
using the default color cycle
(default for non-numeric ``hue`` variables)

markersize: Hashable or None, optional
scatter only. Variable by which to vary size of scattered points.
linewidth: Hashable or None, optional
Expand Down Expand Up @@ -935,6 +926,19 @@ def newplotfunc(
warnings.warn(msg, DeprecationWarning, stacklevel=2)
del args

if hue_style is not None:
# TODO: Not used since 2022.10. Deprecated since 2023.07.
warnings.warn(
(
"hue_style is no longer used for plot1d plots "
"and the argument will eventually be removed. "
"Convert numbers to string for a discrete hue "
"and use add_legend or add_colorbar to control which guide to display."
),
DeprecationWarning,
stacklevel=2,
)

_is_facetgrid = kwargs.pop("_is_facetgrid", False)

if plotfunc.__name__ == "scatter":
Expand Down
10 changes: 10 additions & 0 deletions xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,16 @@ def data_is_numeric(self) -> bool:
>>> a = xr.DataArray([0.5, 0, 0, 0.5, 2, 3])
>>> _Normalize(a).data_is_numeric
True

>>> # TODO: Datetime should be numeric right?
>>> a = xr.DataArray(pd.date_range("2000-1-1", periods=4))
>>> _Normalize(a).data_is_numeric
False

# TODO: Timedelta should be numeric right?
>>> a = xr.DataArray(pd.timedelta_range("-1D", periods=4, freq="D"))
>>> _Normalize(a).data_is_numeric
True
"""
return self._data_is_numeric

Expand Down
33 changes: 21 additions & 12 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2708,23 +2708,32 @@ def test_bad_args(
x=x, y=y, hue=hue, add_legend=add_legend, add_colorbar=add_colorbar
)

@pytest.mark.xfail(reason="datetime,timedelta hue variable not supported.")
@pytest.mark.parametrize("hue_style", ["discrete", "continuous"])
def test_datetime_hue(self, hue_style: Literal["discrete", "continuous"]) -> None:
def test_datetime_hue(self) -> None:
ds2 = self.ds.copy()

# TODO: Currently plots as categorical, should it behave as numerical?
ds2["hue"] = pd.date_range("2000-1-1", periods=4)
ds2.plot.scatter(x="A", y="B", hue="hue", hue_style=hue_style)
ds2.plot.scatter(x="A", y="B", hue="hue")

ds2["hue"] = pd.timedelta_range("-1D", periods=4, freq="D")
ds2.plot.scatter(x="A", y="B", hue="hue", hue_style=hue_style)
ds2.plot.scatter(x="A", y="B", hue="hue")

@pytest.mark.parametrize("hue_style", ["discrete", "continuous"])
def test_facetgrid_hue_style(
self, hue_style: Literal["discrete", "continuous"]
) -> None:
g = self.ds.plot.scatter(
x="A", y="B", row="row", col="col", hue="hue", hue_style=hue_style
)
def test_facetgrid_hue_style(self) -> None:
ds2 = self.ds.copy()

# Numbers plots as continous:
g = ds2.plot.scatter(x="A", y="B", row="row", col="col", hue="hue")
assert isinstance(g._mappables[-1], mpl.collections.PathCollection)

# Datetimes plots as categorical:
# TODO: Currently plots as categorical, should it behave as numerical?
ds2["hue"] = pd.date_range("2000-1-1", periods=4)
g = ds2.plot.scatter(x="A", y="B", row="row", col="col", hue="hue")
assert isinstance(g._mappables[-1], mpl.collections.PathCollection)

# Strings plots as categorical:
ds2["hue"] = ["a", "a", "b", "b"]
g = ds2.plot.scatter(x="A", y="B", row="row", col="col", hue="hue")
assert isinstance(g._mappables[-1], mpl.collections.PathCollection)

@pytest.mark.parametrize(
Expand Down