diff --git a/notebooks/multi_roi_area_astimate.ipynb b/notebooks/multi_roi_area_astimate.ipynb index e1152739..84245143 100644 --- a/notebooks/multi_roi_area_astimate.ipynb +++ b/notebooks/multi_roi_area_astimate.ipynb @@ -121,7 +121,63 @@ "metadata": {}, "outputs": [], "source": [ - "run_area_estimates_config(config, show_output_charts=True)" + "anual_estimates = run_area_estimates_config(config, show_output_charts=True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "def plot_crop_area_with_confidence(anual_estimates):\n", + " \"\"\"\n", + " This function takes in a dictionary with crop area data and plots a bar chart \n", + " with 95% confidence intervals for each region and year.\n", + "\n", + " Parameters:\n", + " data (dict): A dictionary where keys are region names and values contain \n", + " crop area data, confidence intervals, and years.\n", + " \"\"\"\n", + " regions = list(anual_estimates.keys())\n", + " years = [2022, 2023]\n", + "\n", + " crop_areas = np.array([anual_estimates[region]['crop area'] for region in regions])\n", + " crop_ci = np.array([anual_estimates[region]['95%CI crop'] for region in regions])\n", + "\n", + " fig, ax = plt.subplots(figsize=(10, 6))\n", + "\n", + " bar_width = 0.35\n", + " index = np.arange(len(regions))\n", + "\n", + " for i, year in enumerate(years):\n", + " ax.bar(index + i * bar_width, crop_areas[:, i], bar_width,\n", + " yerr=crop_ci[:, i], label=f'Year {year}', capsize=5)\n", + "\n", + " ax.set_xlabel('Region')\n", + " ax.set_ylabel('Crop Area (hectares)')\n", + " ax.set_title('Crop Area by Region with 95% Confidence Intervals (2022 vs 2023)')\n", + " ax.set_xticks(index + bar_width / 2)\n", + " ax.set_xticklabels(regions)\n", + " ax.legend()\n", + "\n", + " ax.set_axisbelow(True)\n", + " ax.grid(True, which='both', axis='y', linestyle='--', linewidth=0.7)\n", + "\n", + " plt.tight_layout()\n", + " plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "plot_crop_area_with_confidence(anual_estimates)" ] } ],