{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "86727581",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import numpy as np\n",
    "from matplotlib.colors import TwoSlopeNorm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "12cfd5fb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 82460 characters]",
      "text/plain": [
       "<Figure size 1200x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "data = pd.read_csv('occupation_ratios.csv')\n",
    "data['gender_delta'] = data['women_ratio'] - 0.5\n",
    "\n",
    "sns.set_style(\"whitegrid\")\n",
    "plt.rcParams.update({'font.size': 14})\n",
    "fig, ax = plt.subplots(figsize=(12, 6))\n",
    "\n",
    "xlims = ax.get_xlim()\n",
    "ylims = ax.get_ylim()\n",
    "cmap = plt.get_cmap('RdBu_r')\n",
    "\n",
    "X = np.linspace(-0.5, 0.5, 256)\n",
    "Y = np.linspace(0, 1, 256)\n",
    "gradient = np.tile(X, (256, 1))\n",
    "\n",
    "ax.imshow(gradient, aspect='auto', cmap=cmap, extent=[-0.5, 0.5, -0.5, len(data['occupation']) - 0.5], zorder=-1)\n",
    "norm = TwoSlopeNorm(vmin=-0.5, vcenter=0, vmax=0.5)\n",
    "ax.barh(data['occupation'], data['gender_delta'], color='white', edgecolor='black')\n",
    "ax.axvline(x=0, color='black', linestyle='--', linewidth=2, label='50% Ratio')\n",
    "ax.set_ylabel('Occupation', fontsize=12)\n",
    "ax.set_xlabel('    ← Male dominated   Female dominated →', fontsize=12)\n",
    "ax.set_title('Gender imbalance across occupations', fontsize=16)\n",
    "ax.set_xlim(-0.5, 0.5)\n",
    "tick_locations = [-0.5, -0.25, 0, 0.25, 0.5]\n",
    "tick_labels = ['100% Male', '75% Male', '50% Ratio', '75% Female', '100% Female']\n",
    "ax.set_xticks(tick_locations)\n",
    "ax.set_xticklabels(tick_labels)\n",
    "\n",
    "plt.tight_layout()\n",
    "plt.savefig('gender_imbalance_horizontal_gradient_large_text.png')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "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.10.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
