{
 "cells": [
  {
   "cell_type": "raw",
   "id": "ac7814b6-1e2c-4f0e-991b-7fe78fca4346",
   "metadata": {},
   "source": [
    ".. currentmodule:: seaborn.objects"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9252d5a5-8af1-4f99-b799-ee044329fb23",
   "metadata": {
    "tags": [
     "hide"
    ]
   },
   "outputs": [],
   "source": [
    "import seaborn.objects as so\n",
    "from seaborn import load_dataset\n",
    "mpg = load_dataset(\"mpg\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a6ee48da-ff1e-41eb-95ec-9f2dd12bdb63",
   "metadata": {},
   "source": [
    "Plot one dependent variable against multiple independent variables by assigning `y` and pairing on `x`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "56ab58b6-ccdf-4938-a8e0-cbe2de8d6749",
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    so.Plot(mpg, y=\"acceleration\")\n",
    "    .pair(x=[\"displacement\", \"weight\"])\n",
    "    .add(so.Dots())\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c37e0543-d022-4079-b58a-8f8af90b29c8",
   "metadata": {},
   "source": [
    "Show multiple pairwise relationships by passing lists to both `x` and `y`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "39b5298d-d578-4284-8fab-415d2c03022d",
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    so.Plot(mpg)\n",
    "    .pair(x=[\"displacement\", \"weight\"], y=[\"horsepower\", \"acceleration\"])\n",
    "    .add(so.Dots())\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "09bf54ad-bf55-4e26-8566-5af62bf29c51",
   "metadata": {},
   "source": [
    "When providing lists for both `x` and `y`, pass `cross=False` to pair each position in the list rather than showing all pairwise relationships:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c70ca7d8-79ee-4c7a-ae91-2088e965b1f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    so.Plot(mpg)\n",
    "    .pair(\n",
    "        x=[\"weight\", \"acceleration\"],\n",
    "        y=[\"displacement\", \"horsepower\"],\n",
    "        cross=False,\n",
    "    )\n",
    "    .add(so.Dots())\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79beadec-038d-40f0-8783-749474d48eac",
   "metadata": {},
   "source": [
    "When plotting against several `x` or `y` variables, it is possible to `wrap` the subplots to produce a two-dimensional grid:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2bf2d87f-a940-426c-bdff-8bf80696b7a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    so.Plot(mpg, y=\"mpg\")\n",
    "    .pair(x=[\"displacement\", \"weight\", \"horsepower\", \"cylinders\"], wrap=2)\n",
    "    .add(so.Dots())\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6304faed-2466-49eb-a8c2-d9d635938b78",
   "metadata": {},
   "source": [
    "Pairing can be combined with faceting, either pairing on `y` and faceting on `col` or pairing on `x` and faceting on `row`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bea235cd-e9c1-4119-a683-871e60b149ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    so.Plot(mpg, x=\"weight\")\n",
    "    .pair(y=[\"horsepower\", \"acceleration\"])\n",
    "    .facet(col=\"origin\")\n",
    "    .add(so.Dots())\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ded931d2-95f1-4e09-8e24-f8b687f8f052",
   "metadata": {},
   "source": [
    "While typically convenient to assign pairing variables as references to the common `data`, it's also possible to pass a list of vectors:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "66e0cb77-094b-4144-b086-15bab106ca9f",
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    so.Plot(mpg[\"weight\"])\n",
    "    .pair(y=[mpg[\"horsepower\"], mpg[\"acceleration\"]])\n",
    "    .add(so.Dots())\n",
    ")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "7bef3310-87f6-44f6-be6a-e30effaa7a70",
   "metadata": {},
   "source": [
    "When customizing the plot through methods like :meth:`Plot.label`, :meth:`Plot.limit`, or :meth:`Plot.scale`, you can refer to the individual coordinate variables as `x0`, `x1`, etc.:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d6ce8868-55c0-4c44-8fed-937771b762ee",
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    so.Plot(mpg, y=\"mpg\")\n",
    "    .pair(x=[\"weight\", \"displacement\"])\n",
    "    .label(x0=\"Weight (lb)\", x1=\"Displacement (cu in)\", y=\"MPG\")\n",
    "    .add(so.Dots())\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "358d409f-8b7c-4901-8eec-b2cf51731483",
   "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
}
