{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-03-10T12:02:04.087452Z",
     "start_time": "2025-03-10T12:02:04.085515Z"
    }
   },
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.ticker as mtick\n",
    "\n",
    "base_ratio = 1.618\n",
    "plt.style.use('seaborn-v0_8-whitegrid')\n",
    "\n",
    "output_dir = \"/home/alex/projects/master-thesis/thesis/resources/figures/\""
   ],
   "outputs": [],
   "execution_count": 37
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-10T12:03:07.884280Z",
     "start_time": "2025-03-10T12:03:07.881628Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def plot(plot_data: dict, save_to_file: bool = False) -> None:\n",
    "    base_size = plot_data[\"base_size\"]\n",
    "    plt.figure(figsize=(base_size * base_ratio, base_size))\n",
    "    for data_item in plot_data[\"plot_data\"]:\n",
    "        plt.plot(data_item[\"data\"], label=data_item[\"label\"], color=data_item[\"color\"])\n",
    "    base_font_modifier = plot_data[\"base_font_modifier\"]\n",
    "    plt.title(plot_data[\"title\"], fontsize=int(14 * base_font_modifier), fontweight='bold')\n",
    "    plt.xlabel(plot_data['x_label'], fontsize=int(12 * base_font_modifier))\n",
    "    plt.ylabel(plot_data['y_label'], fontsize=int(12 * base_font_modifier))\n",
    "    plt.xticks(fontsize=int(10 * base_font_modifier))\n",
    "    plt.yticks(fontsize=int(10 * base_font_modifier))\n",
    "    plt.gca().yaxis.set_major_formatter(mtick.PercentFormatter(1, decimals=0))\n",
    "    plt.ylim(plot_data[\"y_lim\"])\n",
    "    plt.xlim(plot_data[\"x_lim\"])\n",
    "    plt.grid(which='major', linestyle='-', linewidth='0.5')\n",
    "    plt.tight_layout()\n",
    "    if len(plot_data[\"plot_data\"]) > 1:\n",
    "        plt.legend()\n",
    "    if save_to_file:\n",
    "        plt.savefig(output_dir + plot_data[\"plot_name\"] + \".png\", dpi=300, bbox_inches='tight')\n",
    "    plt.show()\n"
   ],
   "id": "73f23f7a578d034",
   "outputs": [],
   "execution_count": 44
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-10T12:03:09.659763Z",
     "start_time": "2025-03-10T12:03:09.444196Z"
    }
   },
   "cell_type": "code",
   "source": [
    "indices_relative_to_start = np.arange(-5, 1)\n",
    "pregnancy_chance_data = [0.02, 0.07, 0.125, 0.24, 0.3, 0.18]\n",
    "pregnancy_chance_data = pd.Series(pregnancy_chance_data, index=indices_relative_to_start)\n",
    "plot_data = {\n",
    "    \"plot_name\": \"background_pregnancy_chance_over_time\",\n",
    "    \"plot_data\": [\n",
    "        {\n",
    "            \"data\": pregnancy_chance_data,\n",
    "            \"label\": \"Pregnancy chance\",\n",
    "            \"color\": \"blue\",\n",
    "        },\n",
    "    ],\n",
    "    \"title\": \"Pregnancy chance over time\",\n",
    "    \"x_label\": \"Day relative to ovulation day\",\n",
    "    \"y_label\": \"Pregnancy chance\",\n",
    "    \"base_size\": 6,\n",
    "    \"base_font_modifier\": 2,\n",
    "    \"y_lim\": (0, 0.35),\n",
    "    \"x_lim\": (-5.5, 0.5),\n",
    "}\n",
    "plot(plot_data, save_to_file=True)\n"
   ],
   "id": "44efa1e412255ca",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 970.8x600 with 1 Axes>"
      ],
      "image/png": "[encoded data, 79448 characters]"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "execution_count": 45
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
