{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2923956c-f141-4ecb-ab08-e819099f0fa9",
   "metadata": {
    "tags": [
     "hide"
    ]
   },
   "outputs": [],
   "source": [
    "import seaborn.objects as so\n",
    "from seaborn import load_dataset\n",
    "dowjones = load_dataset(\"dowjones\")\n",
    "fmri = load_dataset(\"fmri\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05468ecf-d2f5-46f0-ba43-ea13aba0ebd2",
   "metadata": {},
   "source": [
    "The mark draws a connecting line between sorted observations:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "acd5788f-e62b-497c-a109-f0bc02b8cae9",
   "metadata": {},
   "outputs": [],
   "source": [
    "so.Plot(dowjones, \"Date\", \"Price\").add(so.Line())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "94efb077-49a5-4214-891a-c68f89c79926",
   "metadata": {},
   "source": [
    "Change the orientation to connect observations along the opposite axis (`orient=\"y\"` is redundant here; the plot would detect that the date variable has a lower orientation priority than the price variable):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c5db48f-1c88-4905-a5f5-2ae96ceb0f95",
   "metadata": {},
   "outputs": [],
   "source": [
    "so.Plot(dowjones, x=\"Price\", y=\"Date\").add(so.Line(), orient=\"y\")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "77bd0b1e-d9d1-4741-9821-83cec708e877",
   "metadata": {},
   "source": [
    "To replicate the same line multiple times, assign a `group` variable (but consider using :class:`Lines` here instead):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2c1b699c-4e42-4461-a7fb-0d664ef8fe1b",
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    fmri\n",
    "    .query(\"region == 'parietal' and event == 'stim'\")\n",
    "    .pipe(so.Plot, \"timepoint\", \"signal\")\n",
    "    .add(so.Line(color=\".2\", linewidth=1), group=\"subject\")\n",
    ")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "c09cc6a1-a86b-48b7-b276-e0e9125d279e",
   "metadata": {},
   "source": [
    "When mapping variables to properties like `color` or `linestyle`, stat transforms are computed within each grouping:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "83b8c68d-a1ae-4bfb-b3dc-4a11bbe85cbc",
   "metadata": {},
   "outputs": [],
   "source": [
    "p = so.Plot(fmri, \"timepoint\", \"signal\", color=\"region\", linestyle=\"event\")\n",
    "p.add(so.Line(), so.Agg())"
   ]
  },
  {
   "cell_type": "raw",
   "id": "c9390f58-0fb1-47ba-8b86-bde4c41e6d1d",
   "metadata": {},
   "source": [
    "Combine with :class:`Band` to show an error bar:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b6ab0006-0f28-4992-b687-41889a424684",
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    p\n",
    "    .add(so.Line(), so.Agg())\n",
    "    .add(so.Band(), so.Est(), group=\"event\")\n",
    ")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "e567df5c-6675-423f-bcd8-94cb3a400251",
   "metadata": {},
   "source": [
    "Add markers to indicate values where the data were sampled:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2541701c-1a2c-44dd-b300-6551861c8b98",
   "metadata": {},
   "outputs": [],
   "source": [
    "p.add(so.Line(marker=\"o\", edgecolor=\"w\"), so.Agg(), linestyle=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a25d0379-b374-4539-82a4-00ce37245e1b",
   "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
}
