{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9252d5a5-8af1-4f99-b799-ee044329fb23",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": [
     "hide"
    ]
   },
   "outputs": [],
   "source": [
    "import seaborn.objects as so\n",
    "from seaborn import load_dataset\n",
    "penguins = load_dataset(\"penguins\")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "fb32137a-e882-4222-9463-b8cf0ee1c8bd",
   "metadata": {
    "editable": true,
    "raw_mimetype": "",
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "Use strings to override default labels:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "65b4320e-6fb9-48ed-9132-53b0d21b85e6",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "p = (\n",
    "    so.Plot(penguins, x=\"bill_length_mm\", y=\"bill_depth_mm\")\n",
    "    .add(so.Dot(), color=\"species\")\n",
    ")\n",
    "p.label(x=\"Length\", y=\"Depth\", color=\"\")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "a39626d2-76f5-40a9-a3fd-6f44dd69bd30",
   "metadata": {
    "editable": true,
    "raw_mimetype": "",
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "Pass a function to *modify* the default label:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c3540c54-1c91-4d55-8f58-cd758abbe2fd",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "p.label(color=str.capitalize)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "68f3b321-0755-4ef1-a9e6-bcff61a9178d",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "Use this method to set the title for a single-axes plot:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "12d23c6e-781f-4b5c-a6b0-3ea0317ab7fb",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "p.label(title=\"Penguin species exhibit distinct bill shapes\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e0bcb80-0929-4ab9-b5c0-13bb3d8e4484",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "When faceting, the `title` parameter will modify default titles:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "da1516b7-b823-41c0-b251-01bdecb6a4e6",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "p.facet(\"sex\").label(title=str.upper)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bb439eae-6cc3-4a6c-bef2-b4b7746edbd1",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "And the `col`/`row` parameters will add labels to the title for each facet:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e0d49ba9-0507-4358-b477-2e0253f0df8f",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "p.facet(\"sex\").label(col=\"Sex:\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "99471c06-1b1a-4ef5-844c-5f4aa8f322f5",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "If more customization is needed, a format string can work well:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "848be3a3-5a2c-4b98-918f-825257be85ae",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "p.facet(\"sex\").label(title=\"{} penguins\".format)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "94012def-dd7c-48f4-8830-f77a3bf7299b",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "p"
   ]
  },
  {
   "cell_type": "raw",
   "id": "e9b669e9-fd3d-4292-9c8d-e5fb093932b2",
   "metadata": {
    "editable": true,
    "raw_mimetype": "",
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "When adding labels for each layer, the `legend=` parameter sets the title for the legend:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "78d22763-3f92-4be1-bc3f-bc24ad39da70",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "(\n",
    "    so.Plot(penguins, x=\"species\")\n",
    "    .add(so.Line(color=\"C1\"), so.Agg(), y=\"bill_length_mm\", label=\"length\")\n",
    "    .add(so.Line(color=\"C2\"), so.Agg(), y=\"bill_depth_mm\", label=\"depth\")\n",
    "    .label(legend=\"Measurement\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5c7a7b91-bb5c-4bf5-99f8-719a220e3b36",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "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
}
