{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "87244f49-8cf2-4668-a556-a8c7828b31bf",
   "metadata": {
    "tags": [
     "hide"
    ]
   },
   "outputs": [],
   "source": [
    "import seaborn.objects as so\n",
    "from seaborn import load_dataset\n",
    "titanic = load_dataset(\"titanic\").sort_values(\"alive\", ascending=False)"
   ]
  },
  {
   "cell_type": "raw",
   "id": "c9a1a7db-f365-4c5f-85ae-1f00e15b0af9",
   "metadata": {},
   "source": [
    "This transform applies a vertical shift to eliminate overlap between marks with a baseline, such as :class:`Bar` or :class:`Area`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "07579f71-842d-4dc1-98ab-38652409238d",
   "metadata": {},
   "outputs": [],
   "source": [
    "so.Plot(titanic, x=\"class\", color=\"sex\").add(so.Bar(), so.Count(), so.Stack())"
   ]
  },
  {
   "cell_type": "raw",
   "id": "2488a821-3bf1-4bb9-9963-bf726d11925c",
   "metadata": {},
   "source": [
    "Stacking can make it much harder to compare values between groups that get shifted, but it can work well when depicting a part-whole relationship:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dcb8ea58-3cf2-455b-b6b7-98b434f2f152",
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    so.Plot(titanic, x=\"age\", alpha=\"alive\")\n",
    "    .facet(\"sex\")\n",
    "    .add(so.Bars(), so.Hist(binwidth=10), so.Stack())\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b649198f-898e-4103-84bc-d74de71de5a7",
   "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
}
