Skip to content

Commit

Permalink
Add example for Band and update release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaskom committed Oct 5, 2022
1 parent c1f73e9 commit f4d1254
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
30 changes: 27 additions & 3 deletions doc/_docstrings/objects.Band.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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": []
}
],
Expand Down
2 changes: 2 additions & 0 deletions doc/whatsnew/v0.12.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down
2 changes: 1 addition & 1 deletion seaborn/_marks/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion seaborn/_marks/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
Expand Down

0 comments on commit f4d1254

Please sign in to comment.