{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c5279924-93c0-4eee-b2d2-a9b71ed07ee9",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "081b3d58-698b-4ba1-aebf-c4aaed9b31b1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a8fccd4-b5f8-4068-baf3-84e66050b61e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# a: understood the best\n",
    "# b: understood the least\n",
    "# 0: not annotated\n",
    "raw_data = \"\"\"a0aba0\n",
    "ba0000\n",
    "b00a00\n",
    "000a0b\n",
    "0a000b\n",
    "000a0b\n",
    "0000ab\n",
    "0aa00b\n",
    "b0a000\n",
    "0000ab\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9b60f5e7-c012-4a65-8cf5-bbb7eec4486c",
   "metadata": {},
   "outputs": [],
   "source": [
    "d = [list(x) for x in raw_data.split(\"\\n\")]\n",
    "df = pd.DataFrame(d)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c9c45261-1fd9-427d-b7ba-ffa40da43f55",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = df.replace(to_replace=['a', 'b'], value=[\"+\", '-'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e5af7910-6bff-4616-8934-0e6232f03bf0",
   "metadata": {},
   "outputs": [],
   "source": [
    "df[1] = pd.Categorical(df[1], categories=['0', '-', '+'])\n",
    "df[1].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77b2b80f-ff66-44be-b0b3-f2e4b2fe93cb",
   "metadata": {},
   "outputs": [],
   "source": [
    "counts = pd.DataFrame([pd.Categorical(df[c], categories=['0', '-', '+']).value_counts() for c in df.columns])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dcff20e4-cb6f-4d9b-b7c2-de4fef3a1c27",
   "metadata": {},
   "outputs": [],
   "source": [
    "counts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6d71b60a-064f-4d89-b3ee-d8932de35e24",
   "metadata": {},
   "outputs": [],
   "source": [
    "counts.index = pd.Index([\n",
    "    \"Maximize data-ink ratio\",\n",
    "    \"Minimize lie factor\",\n",
    "    \"Minimize chartjunk\",\n",
    "    \"Use scales and labeling well\",\n",
    "    \"Use Color Well\",\n",
    "    \"Use Repetition Well\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0fad5e1a-ce48-4718-bd54-554db3018c84",
   "metadata": {},
   "outputs": [],
   "source": [
    "counts"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c9d8f95-7f1d-45eb-ac74-65b84e7b30c3",
   "metadata": {},
   "source": [
    "In the following two sections, I've started with very basic Seaborn barplots. For practice,\n",
    "* Identify ways to improve the presentation of these plots, grounded in the visualization principles\n",
    "* Make these improvements, either by tweaking the sns call, or adjusting the plot after creation with matplotlib."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9f05320c-2e1b-46da-8cb6-346c891703be",
   "metadata": {},
   "source": [
    "## Best-Understood Principles"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8b79a262-85ef-4ca9-aa82-941882da73ae",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.barplot(counts[\"+\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ba0a7c7-2aa3-45ef-ba06-ffe24486d267",
   "metadata": {},
   "source": [
    "## Least-Understood Principles"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0bd6cbb2-2593-4f54-846a-104f7e5fc38d",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.barplot(counts, x=\"-\", y=counts.index)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.12.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
