{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0bfee8b6-1e3e-499d-96ae-735a5c230b32",
   "metadata": {
    "tags": [
     "hide"
    ]
   },
   "outputs": [],
   "source": [
    "import seaborn.objects as so\n",
    "from seaborn import load_dataset\n",
    "healthexp = load_dataset(\"healthexp\")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "43adf565-2843-48fe-a12a-1a65bc9fce9f",
   "metadata": {},
   "source": [
    "By default, this transform scales each group relative to its maximum value:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6262c89d-56cd-41b4-8276-0bf737b02f29",
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    so.Plot(healthexp, x=\"Year\", y=\"Spending_USD\", color=\"Country\")\n",
    "    .add(so.Lines(), so.Norm())\n",
    "    .label(y=\"Spending relative to maximum amount\")\n",
    ")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "5941b47a-7f2f-4540-9944-c6a16e7eec75",
   "metadata": {},
   "source": [
    "Use `where` to constrain the values used to define a baseline, and `percent` to scale the output:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8142d0b4-1b91-4ba9-bc60-3df148130ff9",
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    so.Plot(healthexp, x=\"Year\", y=\"Spending_USD\", color=\"Country\")\n",
    "    .add(so.Lines(), so.Norm(where=\"x == x.min()\", percent=True))\n",
    "    .label(y=\"Percent change in spending from 1970 baseline\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2f2d2d33-8a92-44fb-b37a-24dee23a7d75",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py310",
   "language": "python",
   "name": "py310"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
