Skip to content

Commit

Permalink
multi-roi notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
Gedeon Muhawenayo authored and Gedeon Muhawenayo committed Sep 22, 2024
1 parent c4932c2 commit 2ab483f
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion notebooks/multi_roi_area_astimate.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
]
}
],
Expand Down

0 comments on commit 2ab483f

Please sign in to comment.