zcahjl3/figmirror-code-aug10
0
1# Variation: ChartType=Multi-Axes Chart, Library=matplotlib2import pandas as pd3import matplotlib.pyplot as plt4 5# ----- Updated Data (minor tweaks, added Colombia) -----6countries = [7 "South Africa", "Thailand", "Venezuela", "Chile", "Argentina",8 "Nigeria", "India", "Kenya", "Bangladesh (SA)", "Ethiopia", "Ghana",9 "Uganda", "Mozambique", "Rwanda", "Eritrea", "Tanzania", "Zambia",10 "Namibia", "Botswana", "Peru", "Colombia"11]12 13# Slightly adjusted 2024 shares (+0.2 on most, new value for Colombia)14base_2024 = [15 17.1, 57.7, 37.8, 31.3, 25.3,16 44.8, 22.9, 28.4, 34.0, 31.4,17 27.3, 27.8, 31.4, 32.9, 29.3,18 20.8, 25.5, 22.3, 18.8, 30.2,19 28.520]21 22region_map = {23 "South Africa": "Sub‑Saharan Africa", "Nigeria": "Sub‑Saharan Africa",24 "Kenya": "Sub‑Saharan Africa", "Ethiopia": "Sub‑Saharan Africa",25 "Ghana": "Sub‑Saharan Africa", "Uganda": "Sub‑Saharan Africa",26 "Mozambique": "Sub‑Saharan Africa", "Rwanda": "Sub‑Saharan Africa",27 "Eritrea": "Sub‑Saharan Africa", "Tanzania": "Sub‑Saharan Africa",28 "Zambia": "Sub‑Saharan Africa", "Namibia": "Sub‑Saharan Africa",29 "Botswana": "Sub‑Saharan Africa",30 "India": "South Asia", "Bangladesh (SA)": "South Asia", "Thailand": "South Asia",31 "Venezuela": "Latin America", "Chile": "Latin America", "Argentina": "Latin America",32 "Peru": "Latin America", "Colombia": "Latin America"33}34 35records = []36for country, v2024 in zip(countries, base_2024):37 v2022 = round(v2024 - 1.5, 1) # approximate 2022 value38 v2023 = round(v2024 - 0.5, 1) # approximate 2023 value39 avg_share = round((v2022 + v2023 + v2024) / 3, 2)40 growth_rate = round((v2024 - v2022) / v2022 * 100, 2) # % increase from 2022 to 202441 records.append({42 "Country": country,43 "Region": region_map[country],44 "AvgShare": avg_share,45 "GrowthRate": growth_rate46 })47 48df = pd.DataFrame(records)49 50# Sort by AvgShare for clearer visual ordering51df = df.sort_values("AvgShare", ascending=False)52 53# ----- Multi‑Axes Chart (Bar + Line) -----54fig, ax1 = plt.subplots(figsize=(12, 6))55 56# Bar chart for average share57bars = ax1.bar(58 df["Country"],59 df["AvgShare"],60 color=plt.cm.Paired(range(len(df))),61 label="Avg Share (%)"62)63ax1.set_xlabel("Country")64ax1.set_ylabel("Average Female Employment Share (%)", color="tab:blue")65ax1.tick_params(axis="y", labelcolor="tab:blue")66ax1.set_xticklabels(df["Country"], rotation=45, ha="right")67 68# Secondary y‑axis for growth rate69ax2 = ax1.twinx()70line = ax2.plot(71 df["Country"],72 df["GrowthRate"],73 color="tab:red",74 marker="o",75 linewidth=2,76 label="Growth Rate (2022‑2024) %"77)78ax2.set_ylabel("Growth Rate (%)", color="tab:red")79ax2.tick_params(axis="y", labelcolor="tab:red")80 81# Unified legend82handles = [bars, line[0]]83labels = [h.get_label() for h in handles]84ax1.legend(handles, labels, loc="upper left")85 86plt.title("Average Vulnerable Female Employment Share & Growth (2022‑2024) by Country")87plt.tight_layout()88plt.savefig("female_employment_multi_axes.png", dpi=300)89plt.close()