Initial
This commit is contained in:
84
notebooks/plot_world_map.ipynb
Normal file
84
notebooks/plot_world_map.ipynb
Normal file
@@ -0,0 +1,84 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "imports",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"from pyprojroot import here"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "load",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"data = pd.read_csv(here() / 'data/base/data.csv')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "plot",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Calculate mean Bell parameter by country\n",
|
||||
"country_stats = data.groupby('Country').agg({\n",
|
||||
" 'Bell Parameter (S)': 'mean',\n",
|
||||
" 'Study ID': 'count'\n",
|
||||
"}).rename(columns={'Study ID': 'Count'}).sort_values('Bell Parameter (S)', ascending=False)\n",
|
||||
"\n",
|
||||
"fig, ax = plt.subplots(figsize=(14, 8))\n",
|
||||
"\n",
|
||||
"# Horizontal bar chart\n",
|
||||
"countries = country_stats.index[:20] # Top 20\n",
|
||||
"values = country_stats['Bell Parameter (S)'][:20]\n",
|
||||
"counts = country_stats['Count'][:20]\n",
|
||||
"\n",
|
||||
"bars = ax.barh(range(len(countries)), values, color='steelblue', edgecolor='black')\n",
|
||||
"\n",
|
||||
"# Color bars by value\n",
|
||||
"for i, (bar, val) in enumerate(zip(bars, values)):\n",
|
||||
" if val > 2.8:\n",
|
||||
" bar.set_color('#27ae60')\n",
|
||||
" elif val > 2.7:\n",
|
||||
" bar.set_color('#3498db')\n",
|
||||
" else:\n",
|
||||
" bar.set_color('#e67e22')\n",
|
||||
"\n",
|
||||
"# Add classical limit line\n",
|
||||
"ax.axvline(x=2.0, color='red', linestyle='--', linewidth=2, alpha=0.7, label='Classical limit')\n",
|
||||
"\n",
|
||||
"# Add counts as text\n",
|
||||
"for i, (val, count) in enumerate(zip(values, counts)):\n",
|
||||
" ax.text(val + 0.01, i, f'n={int(count)}', va='center', fontsize=9)\n",
|
||||
"\n",
|
||||
"ax.set_yticks(range(len(countries)))\n",
|
||||
"ax.set_yticklabels(countries)\n",
|
||||
"ax.set_xlabel('Mean Bell Parameter (S)', fontsize=12)\n",
|
||||
"ax.set_title('Mean Bell Parameter by Country (Top 20)', fontsize=14)\n",
|
||||
"ax.legend()\n",
|
||||
"ax.grid(True, alpha=0.3, axis='x')\n",
|
||||
"\n",
|
||||
"plt.tight_layout()\n",
|
||||
"plt.savefig(here() / 'output/plots/world_map.png', dpi=300, bbox_inches='tight')"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user