{
 "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\")\n",
    "flights = load_dataset(\"flights\").query(\"year == 1960\")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "4e817cdd-09a3-4cf6-8602-e9665607bfe1",
   "metadata": {},
   "source": [
    "The mark draws discrete bars from a baseline to provided values:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5a4e5ba1-50ce-4060-8eb7-f17fee9080c0",
   "metadata": {},
   "outputs": [],
   "source": [
    "so.Plot(flights[\"month\"], flights[\"passengers\"]).add(so.Bar())"
   ]
  },
  {
   "cell_type": "raw",
   "id": "252cf7b2-7fc8-4085-8174-0126743d8a08",
   "metadata": {},
   "source": [
    "The bars are oriented depending on the x/y variable types and the `orient` parameter:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "81dbbc81-178a-46dd-9acf-2c57d2a7e315",
   "metadata": {},
   "outputs": [],
   "source": [
    "so.Plot(flights[\"passengers\"], flights[\"month\"]).add(so.Bar())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6fddeceb-25b9-4fc1-bae0-4cc4cb612674",
   "metadata": {},
   "source": [
    "A common usecase will be drawing histograms on a variable with a nominal scale:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "08604543-c681-4cd3-943e-b57c0f863b2e",
   "metadata": {},
   "outputs": [],
   "source": [
    "so.Plot(penguins, x=\"species\").add(so.Bar(), so.Hist())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b9af978-fdb0-46aa-9cf9-d3e49e38b344",
   "metadata": {},
   "source": [
    "When mapping additional variables, the bars will overlap by default:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "297f7fef-7c31-40dd-ac68-e0ce7f131528",
   "metadata": {},
   "outputs": [],
   "source": [
    "so.Plot(penguins, x=\"species\", color=\"sex\").add(so.Bar(), so.Hist())"
   ]
  },
  {
   "cell_type": "raw",
   "id": "cd9b7b4a-3150-42b5-b1a8-1c5950ca8703",
   "metadata": {},
   "source": [
    "Apply a move transform, such as a :class:`Dodge` or :class:`Stack` to resolve them:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a13c7594-737c-4215-b2a2-e59fc2d033c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "so.Plot(penguins, x=\"species\", color=\"sex\").add(so.Bar(), so.Hist(), so.Dodge())"
   ]
  },
  {
   "cell_type": "raw",
   "id": "f5f44a6b-610a-4523-a7c2-39c804a60520",
   "metadata": {},
   "source": [
    "A number of properties can be mapped or set:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e5cbf5a9-effb-4550-bdaf-c266dc69d3f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    so.Plot(\n",
    "        penguins, x=\"species\",\n",
    "        color=\"sex\", alpha=\"sex\", edgestyle=\"sex\",\n",
    "    )\n",
    "    .add(so.Bar(edgewidth=2), so.Hist(), so.Dodge(\"fill\"))\n",
    ")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "539144d9-75bc-4eb0-8fed-ca57b516b6d3",
   "metadata": {},
   "source": [
    "Combine with :class:`Range` to plot an estimate with errorbars:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "89233c4a-38e7-4807-b3b4-3b4540ffcf56",
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    so.Plot(penguins, \"body_mass_g\", \"species\", color=\"sex\")\n",
    "    .add(so.Bar(alpha=.5), so.Agg(), so.Dodge())\n",
    "    .add(so.Range(), so.Est(errorbar=\"sd\"), so.Dodge())\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4f6a97a0-2d92-4fd5-ad98-b4299bda1b6b",
   "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
}
