zavavan commited on
Commit
e5730a3
·
verified ·
1 Parent(s): ef12036

Update dashboard.py

Browse files
Files changed (1) hide show
  1. dashboard.py +48 -2
dashboard.py CHANGED
@@ -34,6 +34,8 @@ from bokeh.resources import INLINE
34
  from holoviews.operation.timeseries import rolling, rolling_outlier_std
35
  hv.extension('bokeh')
36
  from scipy.ndimage import gaussian_filter1d
 
 
37
 
38
  import os
39
  os.environ['MPLCONFIGDIR'] = '/tmp/matplotlib'
@@ -380,6 +382,50 @@ def create_overlay_plot(subject_df):
380
  )
381
  return overlay
382
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
383
  def hook1(plot, element):
384
  plot.handles['xaxis'].axis_label_text_color = 'black'
385
  plot.handles['yaxis'].axis_label_text_color = 'black'
@@ -419,12 +465,12 @@ def create_overlay_plots(df):
419
  overlay = hv.Overlay(curves).opts(
420
  opts.Overlay(bgcolor='white',
421
  #padding=-0.1,
422
- show_legend=True,
423
  #legend_position='top_left',
424
  #ylim=(0, max_y + 0.18*max_y),
425
  width=1700,
426
  height=500,
427
- hooks=[legend_hook, hook1, lambda p, _: p.state.update(border_fill_color='white')],
428
 
429
  ),
430
  opts.Curve(
 
34
  from holoviews.operation.timeseries import rolling, rolling_outlier_std
35
  hv.extension('bokeh')
36
  from scipy.ndimage import gaussian_filter1d
37
+ from bokeh.models import Legend, LegendItem
38
+
39
 
40
  import os
41
  os.environ['MPLCONFIGDIR'] = '/tmp/matplotlib'
 
382
  )
383
  return overlay
384
 
385
+ def custom_legend_below(plot, element):
386
+ from bokeh.models import Legend
387
+ p = plot.state
388
+
389
+ # Collect renderers and labels
390
+ renderers = []
391
+ labels = []
392
+ for r in p.renderers:
393
+ if hasattr(r, 'glyph') and hasattr(r, 'name') and r.name:
394
+ renderers.append(r)
395
+ labels.append(r.name)
396
+ elif hasattr(r, 'glyph') and hasattr(r, 'label'):
397
+ renderers.append(r)
398
+ labels.append(r.label.get('value', ''))
399
+
400
+ # If default legends exist, remove them
401
+ p.legend.visible = False
402
+ p.legend.clear()
403
+
404
+ # Create new legend items
405
+ items = [LegendItem(label=label, renderers=[rend]) for label, rend in zip(labels, renderers)]
406
+
407
+ # Create new legend manually
408
+ new_legend = Legend(
409
+ items=items,
410
+ orientation='horizontal',
411
+ location='center',
412
+ background_fill_color='white',
413
+ background_fill_alpha=1.0,
414
+ border_line_color='black',
415
+ label_text_color='black',
416
+ label_text_font_size='12pt',
417
+ spacing=5,
418
+ margin=10,
419
+ label_standoff=5,
420
+ glyph_width=20,
421
+ glyph_height=20,
422
+ columns=8 # Distribute across columns
423
+ )
424
+
425
+ # Attach it below the plot area
426
+ p.add_layout(new_legend, 'below')
427
+
428
+
429
  def hook1(plot, element):
430
  plot.handles['xaxis'].axis_label_text_color = 'black'
431
  plot.handles['yaxis'].axis_label_text_color = 'black'
 
465
  overlay = hv.Overlay(curves).opts(
466
  opts.Overlay(bgcolor='white',
467
  #padding=-0.1,
468
+ show_legend=False,
469
  #legend_position='top_left',
470
  #ylim=(0, max_y + 0.18*max_y),
471
  width=1700,
472
  height=500,
473
+ hooks=[custom_legend_below, hook1, lambda p, _: p.state.update(border_fill_color='white')],
474
 
475
  ),
476
  opts.Curve(