{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "987b9549-532e-4091-a6cf-007d1b23e825",
   "metadata": {
    "tags": [
     "hide"
    ]
   },
   "outputs": [],
   "source": [
    "import seaborn as sns\n",
    "sns.set_theme()"
   ]
  },
  {
   "cell_type": "raw",
   "id": "2c78ca60-e232-44f6-956b-b86b472b1c28",
   "metadata": {},
   "source": [
    "Pass a :class:`DataFrame` to plot with indices as row/column labels:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fad17798-c2e3-4334-abf0-0d46153971fa",
   "metadata": {},
   "outputs": [],
   "source": [
    "glue = sns.load_dataset(\"glue\").pivot(index=\"Model\", columns=\"Task\", values=\"Score\")\n",
    "sns.heatmap(glue)"
   ]
  },
  {
   "cell_type": "raw",
   "id": "f3255c5f-2477-4d13-b4c2-7e56380e9cc2",
   "metadata": {},
   "source": [
    "Use `annot` to represent the cell values with text:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3c9f3c73-c8bc-426e-bc67-dec8f807082e",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.heatmap(glue, annot=True)"
   ]
  },
  {
   "cell_type": "raw",
   "id": "bc412da8-866a-49b7-8496-01fbf06dd908",
   "metadata": {},
   "source": [
    "Control the annotations with a formatting string:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac952d0d-9187-4dff-a560-88430076851a",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.heatmap(glue, annot=True, fmt=\".1f\")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "5eb12725-e9ee-4df0-9708-243d7e0a77b5",
   "metadata": {},
   "source": [
    "Use a separate dataframe for the annotations:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1189a37f-9f74-455a-a09a-c22e056d8ba7",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.heatmap(glue, annot=glue.rank(axis=\"columns\"))"
   ]
  },
  {
   "cell_type": "raw",
   "id": "253dfb7f-aa12-4716-adc2-3a38b003b2c3",
   "metadata": {},
   "source": [
    "Add lines between cells:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5cac673e-9b86-490b-9e67-ec0cf865bede",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.heatmap(glue, annot=True, linewidth=.5)"
   ]
  },
  {
   "cell_type": "raw",
   "id": "b7d3659c-f996-4af3-a612-430d97799c72",
   "metadata": {},
   "source": [
    "Select a different colormap by name:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "86806d72-e784-430e-8320-48f2c91115bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.heatmap(glue, cmap=\"crest\")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "8336fd53-3841-458f-b26c-411efff54d45",
   "metadata": {},
   "source": [
    "Or pass a colormap object:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9944ff33-991f-4138-a951-e3015c0326f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.heatmap(glue, cmap=sns.cubehelix_palette(as_cmap=True))"
   ]
  },
  {
   "cell_type": "raw",
   "id": "52cc4dba-b86a-4da8-9cbd-3f8aa06b43b4",
   "metadata": {},
   "source": [
    "Set the colormap norm (data values corresponding to minimum and maximum points):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b4ddb41e-c075-41a5-8afe-422ad6d105bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.heatmap(glue, vmin=50, vmax=100)"
   ]
  },
  {
   "cell_type": "raw",
   "id": "6e828517-a532-49b1-be11-eda47c50cc37",
   "metadata": {},
   "source": [
    "Use methods on the :class:`matplotlib.axes.Axes` object to tweak the plot:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1aab26fc-2de4-4d4f-ad08-487809573deb",
   "metadata": {},
   "outputs": [],
   "source": [
    "ax = sns.heatmap(glue, annot=True)\n",
    "ax.set(xlabel=\"\", ylabel=\"\")\n",
    "ax.xaxis.tick_top()"
   ]
  }
 ],
 "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
}
