{
 "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",
    "penguins = load_dataset(\"penguins\")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "576cbc86-f869-47b5-a98f-6ee727287a8b",
   "metadata": {},
   "source": [
    "This mark will often be used in the context of a stat transform that adds an errorbar interval:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f6217b85-7479-49fd-aeda-9f435aa0473a",
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    so.Plot(penguins, x=\"body_mass_g\", y=\"species\", color=\"sex\")\n",
    "    .add(so.Dot(), so.Agg(), so.Dodge())\n",
    "    .add(so.Range(), so.Est(errorbar=\"sd\"), so.Dodge())\n",
    ")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "e156ea24-d8b4-4d67-acb5-750034be4dde",
   "metadata": {},
   "source": [
    "One feature (or potential gotcha) is that the mark will pick up properties like `linestyle` and `linewidth`; exclude those properties from the relevant layer if this behavior is undesired:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4bb63ebb-7733-4313-844c-cb7613298da3",
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    so.Plot(penguins, x=\"sex\", y=\"body_mass_g\", linestyle=\"species\")\n",
    "    .facet(\"species\")\n",
    "    .add(so.Line(marker=\"o\"), so.Agg())\n",
    "    .add(so.Range(), so.Est(errorbar=\"sd\"))\n",
    ")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "5387e049-b343-49ea-a943-7dd9c090f184",
   "metadata": {},
   "source": [
    "It's also possible to directly assign the minimum and maximum values for the range:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4e795770-4481-4e23-a49b-e828a1f5cbbd",
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    penguins\n",
    "    .rename_axis(index=\"penguin\")\n",
    "    .pipe(so.Plot, x=\"penguin\", ymin=\"bill_depth_mm\", ymax=\"bill_length_mm\")\n",
    "    .add(so.Range(), color=\"island\")\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2191bec6-a02e-48e0-b92c-69c38826049d",
   "metadata": {},
   "source": [
    "When `min`/`max` variables are neither computed as part of a transform or explicitly assigned, the range will cover the full extent of the data at each unique observation on the orient axis:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "63c6352e-4ef5-4cff-940e-35fa5804b2c7",
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    so.Plot(penguins, x=\"sex\", y=\"body_mass_g\")\n",
    "    .facet(\"species\")\n",
    "    .add(so.Dots(pointsize=6))\n",
    "    .add(so.Range(linewidth=2))\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c215deb1-e510-4631-b999-737f5f41cae2",
   "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
}
