{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Grouped bar chart with labels\n\nThis example shows a how to create a grouped bar chart and how to annotate\nbars with labels.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# data from https://allisonhorst.github.io/palmerpenguins/\n\nimport matplotlib.pyplot as plt\n\nspecies = (\"Adelie\", \"Chinstrap\", \"Gentoo\")\npenguin_means = {\n    'Bill Depth': (18.35, 18.43, 14.98),\n    'Bill Length': (38.79, 48.83, 47.50),\n    'Flipper Length': (189.95, 195.82, 217.19),\n}\n\nfig, ax = plt.subplots(layout='constrained')\n\nres = ax.grouped_bar(penguin_means, tick_labels=species, group_spacing=1)\nfor container in res.bar_containers:\n    ax.bar_label(container, padding=3)\n\n# Add some text for labels, title, etc.\nax.set_ylabel('Length (mm)')\nax.set_title('Penguin attributes by species')\nax.legend(loc='upper left', ncols=3)\nax.set_ylim(0, 250)\n\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ".. admonition:: References\n\n   The use of the following functions, methods, classes and modules is shown\n   in this example:\n\n   - `matplotlib.axes.Axes.bar` / `matplotlib.pyplot.bar`\n   - `matplotlib.axes.Axes.bar_label` / `matplotlib.pyplot.bar_label`\n\n.. tags::\n\n   component: label\n   plot-type: bar\n   level: beginner\n\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "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.14.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}