Update app.py
Browse files
app.py
CHANGED
|
@@ -18,29 +18,38 @@ scenario_map = {"0": "No cleansing", "A": "Urgent cleansing", "B": "Urgent+Low u
|
|
| 18 |
# --- Traffic light plotting utility ---
|
| 19 |
def plot_dimension(dim_col, scenario):
|
| 20 |
value = data.set_index("scenario").loc[scenario, dim_col]
|
| 21 |
-
fig, ax = plt.subplots(figsize=(
|
| 22 |
# Traffic light backgrounds
|
| 23 |
-
ax.axhspan(0, 0.6, color="#FF4D4F", alpha=0.
|
| 24 |
-
ax.axhspan(0.6, 0.8, color="#FFE58F", alpha=0.
|
| 25 |
-
ax.axhspan(0.8, 0.95, color="#52C41A", alpha=0.
|
| 26 |
# Value marker (smaller, thinner)
|
| 27 |
-
ax.axhline(value, color='black', lw=2, xmin=0.
|
| 28 |
-
# Value text
|
| 29 |
-
ax.
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
ax.set_xlim(0, 1)
|
| 32 |
ax.set_ylim(0, 0.95)
|
| 33 |
ax.set_xticks([])
|
| 34 |
ax.set_yticks([0, 0.6, 0.8, 0.95])
|
| 35 |
-
ax.set_yticklabels(["0.0", "0.6", "0.8", "1.0"], fontsize=
|
| 36 |
for spine in ax.spines.values():
|
| 37 |
spine.set_visible(False)
|
| 38 |
ax.spines['left'].set_visible(True)
|
| 39 |
ax.spines['left'].set_linewidth(2)
|
| 40 |
-
#
|
|
|
|
| 41 |
ax.set_title(
|
| 42 |
f"{dim_col.replace('_', ' ').title()}\n({scenario_map[scenario]})",
|
| 43 |
-
fontsize=
|
| 44 |
)
|
| 45 |
plt.tight_layout()
|
| 46 |
return fig
|
|
|
|
| 18 |
# --- Traffic light plotting utility ---
|
| 19 |
def plot_dimension(dim_col, scenario):
|
| 20 |
value = data.set_index("scenario").loc[scenario, dim_col]
|
| 21 |
+
fig, ax = plt.subplots(figsize=(4, 7)) # Wider and taller
|
| 22 |
# Traffic light backgrounds
|
| 23 |
+
ax.axhspan(0, 0.6, color="#FF4D4F", alpha=0.30)
|
| 24 |
+
ax.axhspan(0.6, 0.8, color="#FFE58F", alpha=0.30)
|
| 25 |
+
ax.axhspan(0.8, 0.95, color="#52C41A", alpha=0.30)
|
| 26 |
# Value marker (smaller, thinner)
|
| 27 |
+
ax.axhline(value, color='black', lw=2, xmin=0.25, xmax=0.75)
|
| 28 |
+
# Value text - annotate, inside the plot area, with white outline for readability
|
| 29 |
+
ax.annotate(
|
| 30 |
+
f"{value:.3f}",
|
| 31 |
+
xy=(0.5, value),
|
| 32 |
+
xycoords=('axes fraction', 'data'),
|
| 33 |
+
ha='center', va='bottom',
|
| 34 |
+
fontsize=22, weight='bold',
|
| 35 |
+
color='black',
|
| 36 |
+
bbox=dict(facecolor='white', edgecolor='none', alpha=0.8, boxstyle='round,pad=0.2')
|
| 37 |
+
)
|
| 38 |
+
# Style
|
| 39 |
ax.set_xlim(0, 1)
|
| 40 |
ax.set_ylim(0, 0.95)
|
| 41 |
ax.set_xticks([])
|
| 42 |
ax.set_yticks([0, 0.6, 0.8, 0.95])
|
| 43 |
+
ax.set_yticklabels(["0.0", "0.6", "0.8", "1.0"], fontsize=15)
|
| 44 |
for spine in ax.spines.values():
|
| 45 |
spine.set_visible(False)
|
| 46 |
ax.spines['left'].set_visible(True)
|
| 47 |
ax.spines['left'].set_linewidth(2)
|
| 48 |
+
# Add extra space above title to prevent overlap
|
| 49 |
+
plt.subplots_adjust(top=0.88)
|
| 50 |
ax.set_title(
|
| 51 |
f"{dim_col.replace('_', ' ').title()}\n({scenario_map[scenario]})",
|
| 52 |
+
fontsize=15, weight='bold', pad=10
|
| 53 |
)
|
| 54 |
plt.tight_layout()
|
| 55 |
return fig
|