rishirajpathak commited on
Commit
146f2ba
·
1 Parent(s): 2b8e654

Fixed graph layout: increased spacing, better margins, smaller fonts to prevent overlapping

Browse files
Files changed (1) hide show
  1. app.py +23 -18
app.py CHANGED
@@ -163,15 +163,15 @@ def create_visualizations(predictions_df, load_info, time_period, hours):
163
  step = max(1, len(df) // 150) # Keep ~150 points for faster rendering
164
  df = df.iloc[::step].reset_index(drop=True)
165
 
166
- # Create subplots
167
  fig = make_subplots(
168
  rows=2, cols=2,
169
  subplot_titles=('Emergency Admissions Forecast', 'ICU Demand Forecast',
170
  'Staff Workload Forecast', 'Peak vs Average Comparison'),
171
  specs=[[{"secondary_y": False}, {"secondary_y": False}],
172
  [{"secondary_y": False}, {"type": "bar"}]],
173
- vertical_spacing=0.12,
174
- horizontal_spacing=0.1
175
  )
176
 
177
  # Color scheme
@@ -309,35 +309,40 @@ def create_visualizations(predictions_df, load_info, time_period, hours):
309
  row=2, col=2
310
  )
311
 
312
- # Update layout - all 4 graphs visible at once
313
  fig.update_layout(
314
  title_text=f'Hospital Emergency Predictions - {time_period}',
315
- title_font_size=20,
316
  title_x=0.5,
317
  showlegend=True,
318
- height=1100,
319
  hovermode='x unified',
320
  template='plotly_dark',
321
  legend=dict(
322
  orientation="h",
323
  yanchor="bottom",
324
- y=-0.15,
325
  xanchor="center",
326
- x=0.5
 
327
  ),
328
- margin=dict(l=60, r=60, t=80, b=100)
329
  )
330
 
331
- # Update axes
332
- fig.update_xaxes(title_text="Time", row=1, col=1, showgrid=True, gridcolor='rgba(128,128,128,0.2)')
333
- fig.update_xaxes(title_text="Time", row=1, col=2, showgrid=True, gridcolor='rgba(128,128,128,0.2)')
334
- fig.update_xaxes(title_text="Time", row=2, col=1, showgrid=True, gridcolor='rgba(128,128,128,0.2)')
335
- fig.update_xaxes(title_text="Metric", row=2, col=2, showgrid=True, gridcolor='rgba(128,128,128,0.2)')
 
 
 
 
336
 
337
- fig.update_yaxes(title_text="Admissions/Hour", row=1, col=1, showgrid=True, gridcolor='rgba(128,128,128,0.2)')
338
- fig.update_yaxes(title_text="ICU Beds", row=1, col=2, showgrid=True, gridcolor='rgba(128,128,128,0.2)')
339
- fig.update_yaxes(title_text="Workload Index", row=2, col=1, showgrid=True, gridcolor='rgba(128,128,128,0.2)')
340
- fig.update_yaxes(title_text="Value", row=2, col=2, showgrid=True, gridcolor='rgba(128,128,128,0.2)')
341
 
342
  return fig
343
 
 
163
  step = max(1, len(df) // 150) # Keep ~150 points for faster rendering
164
  df = df.iloc[::step].reset_index(drop=True)
165
 
166
+ # Create subplots with better spacing
167
  fig = make_subplots(
168
  rows=2, cols=2,
169
  subplot_titles=('Emergency Admissions Forecast', 'ICU Demand Forecast',
170
  'Staff Workload Forecast', 'Peak vs Average Comparison'),
171
  specs=[[{"secondary_y": False}, {"secondary_y": False}],
172
  [{"secondary_y": False}, {"type": "bar"}]],
173
+ vertical_spacing=0.18,
174
+ horizontal_spacing=0.12
175
  )
176
 
177
  # Color scheme
 
309
  row=2, col=2
310
  )
311
 
312
+ # Update layout - properly spaced for all 4 graphs
313
  fig.update_layout(
314
  title_text=f'Hospital Emergency Predictions - {time_period}',
315
+ title_font_size=18,
316
  title_x=0.5,
317
  showlegend=True,
318
+ height=1200,
319
  hovermode='x unified',
320
  template='plotly_dark',
321
  legend=dict(
322
  orientation="h",
323
  yanchor="bottom",
324
+ y=-0.08,
325
  xanchor="center",
326
+ x=0.5,
327
+ font=dict(size=10)
328
  ),
329
+ margin=dict(l=80, r=80, t=100, b=120)
330
  )
331
 
332
+ # Update subplot title styling
333
+ for annotation in fig['layout']['annotations']:
334
+ annotation['font'] = dict(size=13, color='#FFFFFF')
335
+
336
+ # Update axes with smaller fonts
337
+ fig.update_xaxes(title_text="Time", title_font_size=11, row=1, col=1, showgrid=True, gridcolor='rgba(128,128,128,0.2)')
338
+ fig.update_xaxes(title_text="Time", title_font_size=11, row=1, col=2, showgrid=True, gridcolor='rgba(128,128,128,0.2)')
339
+ fig.update_xaxes(title_text="Time", title_font_size=11, row=2, col=1, showgrid=True, gridcolor='rgba(128,128,128,0.2)')
340
+ fig.update_xaxes(title_text="Metric", title_font_size=11, row=2, col=2, showgrid=True, gridcolor='rgba(128,128,128,0.2)')
341
 
342
+ fig.update_yaxes(title_text="Admissions/Hour", title_font_size=11, row=1, col=1, showgrid=True, gridcolor='rgba(128,128,128,0.2)')
343
+ fig.update_yaxes(title_text="ICU Beds", title_font_size=11, row=1, col=2, showgrid=True, gridcolor='rgba(128,128,128,0.2)')
344
+ fig.update_yaxes(title_text="Workload Index", title_font_size=11, row=2, col=1, showgrid=True, gridcolor='rgba(128,128,128,0.2)')
345
+ fig.update_yaxes(title_text="Value", title_font_size=11, row=2, col=2, showgrid=True, gridcolor='rgba(128,128,128,0.2)')
346
 
347
  return fig
348