Spaces:
Running
Running
style: enhance Matplotlib chart with premium dark background, value labels, and tight margins
Browse files
app/services/export_service.py
CHANGED
|
@@ -102,16 +102,43 @@ REQUIREMENTS:
|
|
| 102 |
elif s >= 40: colors.append('#3b82f6') # Blue
|
| 103 |
else: colors.append('#10b981') # Emerald
|
| 104 |
|
| 105 |
-
|
| 106 |
-
plt.
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
| 114 |
-
|
|
|
|
| 115 |
plt.close()
|
| 116 |
|
| 117 |
return output_path
|
|
|
|
| 102 |
elif s >= 40: colors.append('#3b82f6') # Blue
|
| 103 |
else: colors.append('#10b981') # Emerald
|
| 104 |
|
| 105 |
+
# Setup modern dark style with baked-in slate background
|
| 106 |
+
fig, ax = plt.subplots(figsize=(10, 6), facecolor='#0b0f19')
|
| 107 |
+
ax.set_facecolor('#0b0f19')
|
| 108 |
+
|
| 109 |
+
# Plot horizontal bars
|
| 110 |
+
bars = ax.barh(descriptions, scores, color=colors, height=0.55)
|
| 111 |
+
|
| 112 |
+
# Customize labels & title
|
| 113 |
+
ax.set_xlabel('Importance Score (%)', color='#94a3b8', fontsize=11, fontweight='bold', labelpad=10)
|
| 114 |
+
ax.set_title('Identified Research Gaps - Priority Map', color='#f8fafc', fontsize=14, fontweight='bold', pad=20)
|
| 115 |
+
|
| 116 |
+
# Grid and spines configuration
|
| 117 |
+
ax.grid(axis='x', linestyle='--', alpha=0.15, color='#94a3b8')
|
| 118 |
+
ax.set_axisbelow(True)
|
| 119 |
+
|
| 120 |
+
# Style ticks and text color
|
| 121 |
+
ax.tick_params(colors='#94a3b8', labelsize=10)
|
| 122 |
+
for spine in ax.spines.values():
|
| 123 |
+
spine.set_color('#1e293b')
|
| 124 |
+
|
| 125 |
+
# Add beautiful value labels next to the bars
|
| 126 |
+
for bar in bars:
|
| 127 |
+
width = bar.get_width()
|
| 128 |
+
ax.text(
|
| 129 |
+
width + 1.5,
|
| 130 |
+
bar.get_y() + bar.get_height()/2,
|
| 131 |
+
f'{int(width)}%',
|
| 132 |
+
va='center',
|
| 133 |
+
ha='left',
|
| 134 |
+
color='#f8fafc',
|
| 135 |
+
fontweight='bold',
|
| 136 |
+
fontsize=9
|
| 137 |
+
)
|
| 138 |
|
| 139 |
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
| 140 |
+
# Save with explicit facecolor to bake the premium dark background into the PNG
|
| 141 |
+
plt.savefig(output_path, facecolor='#0b0f19', edgecolor='none', bbox_inches='tight', dpi=150)
|
| 142 |
plt.close()
|
| 143 |
|
| 144 |
return output_path
|