fork download
  1. # --- Create dataframe (Table CtG1A.3) ---
  2. data = {
  3. "Year": [
  4. *["2020–22"] * 48,
  5. *["2015–17"] * 48
  6. ],
  7. "Indigenous_status": [
  8. *(["Aboriginal and Torres Strait Islander"] * 32 +
  9. ["Non-Indigenous"] * 8 +
  10. ["Difference"] * 8),
  11. *(["Aboriginal and Torres Strait Islander"] * 32 +
  12. ["Non-Indigenous"] * 8 +
  13. ["Difference"] * 8)
  14. ],
  15. "Sex": [
  16. *([ "Males"] * 16 + ["Females"] * 16 + ["Males"] * 4 + ["Females"] * 4 + ["Males"] * 4 + ["Females"] * 4),
  17. *([ "Males"] * 16 + ["Females"] * 16 + ["Males"] * 4 + ["Females"] * 4 + ["Males"] * 4 + ["Females"] * 4)
  18. ],
  19. "Measure": (["Mean", "LCI", "UCI"] * 32)[:96],
  20. "Quintile": (["Q1", "Q2", "Q3", "Q4"] * 24)[:96],
  21. "Value": [
  22. # Aboriginal and Torres Strait Islander 2020–22
  23. 69.5, 71.7, 74.3, 74.6, 69.2, 71.2, 73.4, 73.3, 70.4, 72.6, 75.6, 76.1,
  24. 74.0, 75.7, 78.0, 77.0, 73.8, 75.3, 77.2, 75.7, 75.0, 76.5, 79.2, 78.3,
  25. # Non-Indigenous 2020–22 (Means only)
  26. 78.4, 79.5, 80.8, 82.0,
  27. 82.3, 83.0, 84.0, 84.6,
  28. # Difference 2020–22
  29. 8.9, 7.8, 6.5, 7.4,
  30. 8.3, 7.3, 6.0, 7.6,
  31.  
  32. # Aboriginal and Torres Strait Islander 2015–17
  33. 69.7, 71.8, 72.6, 74.0, 68.9, 70.9, 71.4, 72.8, 70.5, 72.7, 73.8, 75.2,
  34. 73.8, 76.7, 75.9, 77.7, 73.0, 75.8, 74.8, 76.6, 74.6, 77.6, 77.0, 78.8,
  35. # Non-Indigenous 2015–17 (Means only)
  36. 77.8, 79.0, 80.3, 81.6,
  37. 81.9, 82.7, 83.5, 84.5,
  38. # Difference 2015–17
  39. 8.1, 7.2, 7.8, 7.7,
  40. 8.1, 6.0, 7.5, 6.8
  41. ]
  42. }
  43.  
  44. df = pd.DataFrame(data)
  45.  
  46. # --- Clean data ---
  47. df["Quintile"] = pd.Categorical(df["Quintile"], categories=["Q1", "Q2", "Q3", "Q4"], ordered=True)
  48. df["Year"] = df["Year"].astype(str)
  49.  
  50. # --- Filter mean values only for main plot ---
  51. df_mean = df[df["Measure"] == "Mean"]
  52.  
  53. # --- Set plot style ---
  54. sns.set(style="whitegrid", context="talk")
  55.  
  56. # --- Plot 1: Life expectancy by quintile and sex (Indigenous vs Non-Indigenous) ---
  57. plt.figure(figsize=(11.7, 8.3)) # A4 size in inches (landscape)
  58. sns.lineplot(
  59. data=df_mean[df_mean["Indigenous_status"] != "Difference"],
  60. x="Quintile", y="Value",
  61. hue="Sex", style="Indigenous_status",
  62. markers=True, dashes=False, linewidth=2.2
  63. )
  64. plt.title("Life Expectancy by SEIFA (IRSD) Quintile and Indigenous Status\nAustralia, 2015–17 vs 2020–22")
  65. plt.ylabel("Life Expectancy (years)")
  66. plt.xlabel("Socioeconomic Quintile (Q1–Q4)")
  67. plt.legend(title="Sex / Indigenous Status")
  68. plt.tight_layout()
  69. plt.show()
  70.  
  71. # --- Plot 2: Life expectancy gap (Difference group) ---
  72. plt.figure(figsize=(11.7, 8.3)) # A4 size
  73. sns.lineplot(
  74. data=df_mean[df_mean["Indigenous_status"] == "Difference"],
  75. x="Quintile", y="Value",
  76. hue="Sex", style="Year",
  77. markers=True, linewidth=2.2, dashes=True
  78. )
  79. plt.title("Life Expectancy Gap (Aboriginal & Torres Strait Islander vs Non-Indigenous)\nBy Socioeconomic Quintile")
  80. plt.ylabel("Gap (years)")
  81. plt.xlabel("Socioeconomic Quintile (Q1–Q4)")
  82. plt.legend(title="Sex / Year")
  83. plt.tight_layout()
  84. plt.show()
Success #stdin #stdout 0.02s 25252KB
stdin
Standard input is empty
stdout
# --- Create dataframe (Table CtG1A.3) ---
data = {
    "Year": [
        *["2020–22"] * 48,
        *["2015–17"] * 48
    ],
    "Indigenous_status": [
        *(["Aboriginal and Torres Strait Islander"] * 32 +
          ["Non-Indigenous"] * 8 +
          ["Difference"] * 8),
        *(["Aboriginal and Torres Strait Islander"] * 32 +
          ["Non-Indigenous"] * 8 +
          ["Difference"] * 8)
    ],
    "Sex": [
        *([ "Males"] * 16 + ["Females"] * 16 + ["Males"] * 4 + ["Females"] * 4 + ["Males"] * 4 + ["Females"] * 4),
        *([ "Males"] * 16 + ["Females"] * 16 + ["Males"] * 4 + ["Females"] * 4 + ["Males"] * 4 + ["Females"] * 4)
    ],
    "Measure": (["Mean", "LCI", "UCI"] * 32)[:96],
    "Quintile": (["Q1", "Q2", "Q3", "Q4"] * 24)[:96],
    "Value": [
        # Aboriginal and Torres Strait Islander 2020–22
        69.5, 71.7, 74.3, 74.6, 69.2, 71.2, 73.4, 73.3, 70.4, 72.6, 75.6, 76.1,
        74.0, 75.7, 78.0, 77.0, 73.8, 75.3, 77.2, 75.7, 75.0, 76.5, 79.2, 78.3,
        # Non-Indigenous 2020–22 (Means only)
        78.4, 79.5, 80.8, 82.0,
        82.3, 83.0, 84.0, 84.6,
        # Difference 2020–22
        8.9, 7.8, 6.5, 7.4,
        8.3, 7.3, 6.0, 7.6,

        # Aboriginal and Torres Strait Islander 2015–17
        69.7, 71.8, 72.6, 74.0, 68.9, 70.9, 71.4, 72.8, 70.5, 72.7, 73.8, 75.2,
        73.8, 76.7, 75.9, 77.7, 73.0, 75.8, 74.8, 76.6, 74.6, 77.6, 77.0, 78.8,
        # Non-Indigenous 2015–17 (Means only)
        77.8, 79.0, 80.3, 81.6,
        81.9, 82.7, 83.5, 84.5,
        # Difference 2015–17
        8.1, 7.2, 7.8, 7.7,
        8.1, 6.0, 7.5, 6.8
    ]
}

df = pd.DataFrame(data)

# --- Clean data ---
df["Quintile"] = pd.Categorical(df["Quintile"], categories=["Q1", "Q2", "Q3", "Q4"], ordered=True)
df["Year"] = df["Year"].astype(str)

# --- Filter mean values only for main plot ---
df_mean = df[df["Measure"] == "Mean"]

# --- Set plot style ---
sns.set(style="whitegrid", context="talk")

# --- Plot 1: Life expectancy by quintile and sex (Indigenous vs Non-Indigenous) ---
plt.figure(figsize=(11.7, 8.3))  # A4 size in inches (landscape)
sns.lineplot(
    data=df_mean[df_mean["Indigenous_status"] != "Difference"],
    x="Quintile", y="Value",
    hue="Sex", style="Indigenous_status",
    markers=True, dashes=False, linewidth=2.2
)
plt.title("Life Expectancy by SEIFA (IRSD) Quintile and Indigenous Status\nAustralia, 2015–17 vs 2020–22")
plt.ylabel("Life Expectancy (years)")
plt.xlabel("Socioeconomic Quintile (Q1–Q4)")
plt.legend(title="Sex / Indigenous Status")
plt.tight_layout()
plt.show()

# --- Plot 2: Life expectancy gap (Difference group) ---
plt.figure(figsize=(11.7, 8.3))  # A4 size
sns.lineplot(
    data=df_mean[df_mean["Indigenous_status"] == "Difference"],
    x="Quintile", y="Value",
    hue="Sex", style="Year",
    markers=True, linewidth=2.2, dashes=True
)
plt.title("Life Expectancy Gap (Aboriginal & Torres Strait Islander vs Non-Indigenous)\nBy Socioeconomic Quintile")
plt.ylabel("Gap (years)")
plt.xlabel("Socioeconomic Quintile (Q1–Q4)")
plt.legend(title="Sex / Year")
plt.tight_layout()
plt.show()