{
 "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",
    "diamonds = load_dataset(\"diamonds\")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "5cf83822-ceb1-4ce5-8364-069466f7aa40",
   "metadata": {},
   "source": [
    "This mark draws bars between a baseline and a value. In contrast to :class:`Bar`, the bars have a full width and thin edges by default; this makes this mark a better choice for a continuous histogram:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e9b99eaf-695f-41ae-9bd1-bfe406dedb63",
   "metadata": {},
   "outputs": [],
   "source": [
    "p = so.Plot(diamonds, \"price\").scale(x=\"log\")\n",
    "p.add(so.Bars(), so.Hist())"
   ]
  },
  {
   "cell_type": "raw",
   "id": "bc4c0f25-3f7a-4a2c-a032-151da47f5ea3",
   "metadata": {},
   "source": [
    "When mapping the color or other properties, bars will overlap by default; this is usually confusing:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7989211b-7a29-4763-bb97-4ea19cdef081",
   "metadata": {},
   "outputs": [],
   "source": [
    "p.add(so.Bars(), so.Hist(), color=\"cut\")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "f16a3b5d-1ac1-4d9d-9bc6-d4cea7f83a17",
   "metadata": {},
   "source": [
    "Using a move transform, such as :class:`Stack` or :class:`Dodge`, will resolve the overlap (although faceting might often be a better approach):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8933f5f7-1423-4741-b7be-6239ea8b2fee",
   "metadata": {},
   "outputs": [],
   "source": [
    "p.add(so.Bars(), so.Hist(), so.Stack(), color=\"cut\")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "74075e80-0361-4388-a459-cbfa6418df6c",
   "metadata": {},
   "source": [
    "A number of different properties can be set or mapped:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "04fada68-a61b-451c-b3bd-9aaab16b5f29",
   "metadata": {},
   "outputs": [],
   "source": [
    "p.add(so.Bars(edgewidth=0), so.Hist(), so.Stack(), alpha=\"clarity\")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "a14d7d36-9d8b-4024-8653-002e9da946d7",
   "metadata": {},
   "source": [
    "It is possible to draw unfilled bars, but you must override the default edge color:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "21642f8c-99c7-4f61-b3f5-bc1dacc638c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "p.add(so.Bars(fill=False, edgecolor=\"C0\", edgewidth=1.5), so.Hist())"
   ]
  },
  {
   "cell_type": "raw",
   "id": "dce5b6cc-0808-48ec-b4d6-0c0c2e5178d2",
   "metadata": {},
   "source": [
    "It is also possible to narrow the bars, which may be useful for dealing with overlap in some cases:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "166693bf-420c-4ec3-8da2-abc22724952b",
   "metadata": {},
   "outputs": [],
   "source": [
    "hist = so.Hist(binwidth=.075, binrange=(2, 5))\n",
    "(\n",
    "    p.add(so.Bars(), hist)\n",
    "    .add(\n",
    "        so.Bars(color=\".9\", width=.5), hist,\n",
    "        data=diamonds.query(\"cut == 'Ideal'\")\n",
    "    )\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b40b02c4-fb2c-4300-93e4-24ea28bc6ef8",
   "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
}
