{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a8aa6a6a-f6c0-4a6b-9460-2056e58a2e13",
   "metadata": {
    "tags": [
     "hide"
    ]
   },
   "outputs": [],
   "source": [
    "import seaborn as sns\n",
    "sns.set_theme(style=\"whitegrid\")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "1aef2740-ae6e-4a1b-a588-3ad978e2614d",
   "metadata": {},
   "source": [
    "By default, the visual representation will be a jittered strip plot:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "75a49e26-4318-4963-897c-dc0081aebfb3",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = sns.load_dataset(\"titanic\")\n",
    "sns.catplot(data=df, x=\"age\", y=\"class\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db1b8f6d-5264-4200-b81a-b0ee64040a1f",
   "metadata": {},
   "source": [
    "Use `kind` to select a different representation:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "75ecd034-8536-4fe4-8852-a3975dba64dc",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.catplot(data=df, x=\"age\", y=\"class\", kind=\"box\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8aee79a9-b8b3-4129-b6d7-e9e32ae1e634",
   "metadata": {},
   "source": [
    "One advantage is that the legend will be automatically placed outside the plot:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3798aac6-1ff6-4e36-ad83-4742fcb04159",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.catplot(data=df, x=\"age\", y=\"class\", hue=\"sex\", kind=\"boxen\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8a3777e1-90b6-4f4d-9e14-247b6dfd64fe",
   "metadata": {},
   "source": [
    "Additional keyword arguments get passed through to the underlying seaborn function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "afcff2fe-db11-4602-af79-68e4a0380f88",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.catplot(\n",
    "    data=df, x=\"age\", y=\"class\", hue=\"sex\",\n",
    "    kind=\"violin\", bw_adjust=.5, cut=0, split=True,\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a75bf46f-a3d0-4a5d-abcd-b9e85def65b0",
   "metadata": {},
   "source": [
    "Assigning a variable to `col` or `row` will automatically create subplots. Control figure size with the `height` and `aspect` parameters:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "835afcf2-ecc9-4edb-9ec8-24484c5b08fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.catplot(\n",
    "    data=df, x=\"class\", y=\"survived\", col=\"sex\",\n",
    "    kind=\"bar\", height=4, aspect=.6,\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ecf323fe-1e86-47ff-aa50-e8c297cfa125",
   "metadata": {},
   "source": [
    "For single-subplot figures, it is easy to layer different representations:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dc5b0fc0-359c-4219-b04e-171d8c7c8051",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.catplot(data=df, x=\"age\", y=\"class\", kind=\"violin\", color=\".9\", inner=None)\n",
    "sns.swarmplot(data=df, x=\"age\", y=\"class\", size=3)"
   ]
  },
  {
   "cell_type": "raw",
   "id": "26e06ba4-0457-4597-b699-cb0fe8b2be32",
   "metadata": {},
   "source": [
    "Use methods on the returned :class:`FacetGrid` to tweak the presentation:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a43f1914-d868-4060-82df-b3d25553d595",
   "metadata": {},
   "outputs": [],
   "source": [
    "g = sns.catplot(\n",
    "    data=df, x=\"who\", y=\"survived\", col=\"class\",\n",
    "    kind=\"bar\", height=4, aspect=.6,\n",
    ")\n",
    "g.set_axis_labels(\"\", \"Survival Rate\")\n",
    "g.set_xticklabels([\"Men\", \"Women\", \"Children\"])\n",
    "g.set_titles(\"{col_name} {col_var}\")\n",
    "g.set(ylim=(0, 1))\n",
    "g.despine(left=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a529c18c-45bc-4efb-8ae0-c14518349162",
   "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
}
