From f4d12546b4deefab4778a3238e037b37f4198133 Mon Sep 17 00:00:00 2001 From: Michael Waskom Date: Wed, 5 Oct 2022 06:58:35 -0400 Subject: [PATCH] Add example for Band and update release notes --- doc/_docstrings/objects.Band.ipynb | 30 +++++++++++++++++++++++++++--- doc/whatsnew/v0.12.1.rst | 2 ++ seaborn/_marks/area.py | 2 +- seaborn/_marks/line.py | 2 +- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/doc/_docstrings/objects.Band.ipynb b/doc/_docstrings/objects.Band.ipynb index 5419a1935d..bcd1975847 100644 --- a/doc/_docstrings/objects.Band.ipynb +++ b/doc/_docstrings/objects.Band.ipynb @@ -13,7 +13,7 @@ "source": [ "import seaborn.objects as so\n", "from seaborn import load_dataset\n", - "fmri = load_dataset(\"fmri\")\n", + "fmri = load_dataset(\"fmri\").query(\"region == 'parietal'\")\n", "seaice = (\n", " load_dataset(\"seaice\")\n", " .assign(\n", @@ -22,7 +22,7 @@ " )\n", " .query(\"Year >= 1980\")\n", " .astype({\"Year\": str})\n", - " .pivot(\"Day\", \"Year\", \"Extent\")\n", + " .pivot(index=\"Day\", columns=\"Year\", values=\"Extent\")\n", " .filter([\"1980\", \"2019\"])\n", " .dropna()\n", " .reset_index()\n", @@ -90,8 +90,32 @@ }, { "cell_type": "raw", - "id": "4e817cdd-09a3-4cf6-8602-e9665607bfe1", + "id": "9f0c82bf-3457-4ac5-ba48-8930bac03d75", "metadata": {}, + "source": [ + "When min/max values are not explicitly assigned or added in a transform, the band will cover the full extent of the data:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "309f578e-da3d-4dc5-b6ac-a354321334c8", + "metadata": {}, + "outputs": [], + "source": [ + "(\n", + " so.Plot(fmri, x=\"timepoint\", y=\"signal\", color=\"event\")\n", + " .add(so.Line(linewidth=.5), group=\"subject\")\n", + " .add(so.Band())\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4330a3cd-63fe-470a-8e83-09e9606643b5", + "metadata": {}, + "outputs": [], "source": [] } ], diff --git a/doc/whatsnew/v0.12.1.rst b/doc/whatsnew/v0.12.1.rst index 6fe496f19b..a1ea32926c 100644 --- a/doc/whatsnew/v0.12.1.rst +++ b/doc/whatsnew/v0.12.1.rst @@ -4,6 +4,8 @@ v0.12.1 (Unreleased) - |Feature| Added the :class:`objects.Text` mark (:pr:`3051`). +- |Feature| The :class:`Band` and :class:`Range` marks will now cover the full extent of the data if `min` / `max` variables are not explicitly assigned or added in a transform (:pr:`3056`). + - |Fix| Make :class:`objects.PolyFit` robust to missing data (:pr:`3010`). - |Fix| Fixed a bug that caused an exception when more than two layers with the same mappings were added (:pr:`3055`). diff --git a/seaborn/_marks/area.py b/seaborn/_marks/area.py index 373f8234a4..b3602ad7e6 100644 --- a/seaborn/_marks/area.py +++ b/seaborn/_marks/area.py @@ -166,5 +166,5 @@ def _standardize_coordinate_parameters(self, data, orient): other = {"x": "y", "y": "x"}[orient] if not set(data.columns) & {f"{other}min", f"{other}max"}: agg = {f"{other}min": (other, "min"), f"{other}max": (other, "max")} - data = data.groupby(orient, as_index=False).agg(**agg) + data = data.groupby(orient).agg(**agg).reset_index() return data diff --git a/seaborn/_marks/line.py b/seaborn/_marks/line.py index 85bbffb15b..aa83fdaacf 100644 --- a/seaborn/_marks/line.py +++ b/seaborn/_marks/line.py @@ -279,7 +279,7 @@ def _setup_lines(self, split_gen, scales, orient): # TODO what if only one exist? if not set(data.columns) & {f"{other}min", f"{other}max"}: agg = {f"{other}min": (other, "min"), f"{other}max": (other, "max")} - data = data.groupby(orient, as_index=False).agg(**agg) + data = data.groupby(orient).agg(**agg).reset_index() cols = [orient, f"{other}min", f"{other}max"] data = data[cols].melt(orient, value_name=other)[["x", "y"]]