Dama12 commited on
Commit
2e2ba73
·
1 Parent(s): 6ab7381

style: enhance Matplotlib chart with premium dark background, value labels, and tight margins

Browse files
Files changed (1) hide show
  1. app/services/export_service.py +35 -8
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
- plt.figure(figsize=(10, 6))
106
- plt.style.use('dark_background')
107
- bars = plt.barh(descriptions, scores, color=colors)
108
- plt.xlabel('Importance Score (%)')
109
- plt.title('Identified Research Gaps - Priority Map')
110
- plt.grid(axis='x', linestyle='--', alpha=0.3)
111
- plt.tight_layout()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
113
  os.makedirs(os.path.dirname(output_path), exist_ok=True)
114
- plt.savefig(output_path, transparent=True)
 
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