@@ -211,6 +211,16 @@ def display_sidebar(st, d: Constants) -> Parameters:
211
211
format = "%i" ,
212
212
)
213
213
214
+ max_y_axis_set = st .sidebar .checkbox ("Set the Y-axis on graphs to a static value" )
215
+ max_y_axis = None
216
+ if max_y_axis_set :
217
+ max_y_axis = st .sidebar .number_input (
218
+ "Y-axis static value" ,
219
+ value = 500 ,
220
+ format = "%i" ,
221
+ step = 25 ,
222
+ )
223
+
214
224
return Parameters (
215
225
current_hospitalized = current_hospitalized ,
216
226
doubling_time = doubling_time ,
@@ -221,7 +231,8 @@ def display_sidebar(st, d: Constants) -> Parameters:
221
231
222
232
hospitalized = RateLos (hospitalized_rate , hospitalized_los ),
223
233
icu = RateLos (icu_rate , icu_los ),
224
- ventilated = RateLos (ventilated_rate , ventilated_los )
234
+ ventilated = RateLos (ventilated_rate , ventilated_los ),
235
+ max_y_axis = max_y_axis
225
236
)
226
237
227
238
@@ -375,12 +386,23 @@ def write_footer(st):
375
386
376
387
377
388
def new_admissions_chart (
378
- alt , projection_admits : pd .DataFrame , plot_projection_days : int , as_date : bool = False
389
+ alt ,
390
+ projection_admits : pd .DataFrame ,
391
+ plot_projection_days : int ,
392
+ as_date : bool = False ,
393
+ max_y_axis : int = None
379
394
) -> alt .Chart :
380
395
"""docstring"""
381
396
projection_admits = projection_admits .rename (
382
397
columns = {"hosp" : "Hospitalized" , "icu" : "ICU" , "vent" : "Ventilated" }
383
398
)
399
+
400
+ y_scale = alt .Scale ()
401
+
402
+ if max_y_axis is not None :
403
+ y_scale .domain = (0 , max_y_axis )
404
+ y_scale .clamp = True
405
+
384
406
tooltip_dict = {False : "day" , True : "date:T" }
385
407
if as_date :
386
408
projection_admits = add_date_column (projection_admits )
@@ -394,7 +416,7 @@ def new_admissions_chart(
394
416
.mark_line (point = True )
395
417
.encode (
396
418
x = alt .X (** x_kwargs ),
397
- y = alt .Y ("value:Q" , title = "Daily admissions" ),
419
+ y = alt .Y ("value:Q" , title = "Daily admissions" , scale = y_scale ),
398
420
color = "key:N" ,
399
421
tooltip = [
400
422
tooltip_dict [as_date ],
@@ -410,7 +432,8 @@ def admitted_patients_chart(
410
432
alt ,
411
433
census : pd .DataFrame ,
412
434
plot_projection_days : int ,
413
- as_date : bool = False
435
+ as_date : bool = False ,
436
+ max_y_axis : int = None
414
437
) -> alt .Chart :
415
438
"""docstring"""
416
439
census = census .rename (
@@ -427,13 +450,19 @@ def admitted_patients_chart(
427
450
else :
428
451
x_kwargs = {"shorthand" : "day" , "title" : "Days from today" }
429
452
453
+ y_scale = alt .Scale ()
454
+
455
+ if max_y_axis is not None :
456
+ y_scale .domain = (0 , max_y_axis )
457
+ y_scale .clamp = True
458
+
430
459
return (
431
460
alt .Chart (census .head (plot_projection_days ))
432
461
.transform_fold (fold = ["Hospital Census" , "ICU Census" , "Ventilated Census" ])
433
462
.mark_line (point = True )
434
463
.encode (
435
464
x = alt .X (** x_kwargs ),
436
- y = alt .Y ("value:Q" , title = "Census" ),
465
+ y = alt .Y ("value:Q" , title = "Census" , scale = y_scale ),
437
466
color = "key:N" ,
438
467
tooltip = [
439
468
tooltip_dict [as_date ],
@@ -449,7 +478,8 @@ def additional_projections_chart(
449
478
alt ,
450
479
i : np .ndarray ,
451
480
r : np .ndarray ,
452
- as_date : bool = False
481
+ as_date : bool = False ,
482
+ max_y_axis : int = None
453
483
) -> alt .Chart :
454
484
dat = pd .DataFrame ({"Infected" : i , "Recovered" : r })
455
485
dat ["day" ] = dat .index
@@ -459,26 +489,40 @@ def additional_projections_chart(
459
489
else :
460
490
x_kwargs = {"shorthand" : "day" , "title" : "Days from today" }
461
491
492
+ y_scale = alt .Scale ()
493
+
494
+ if max_y_axis is not None :
495
+ y_scale .domain = (0 , max_y_axis )
496
+ y_scale .clamp = True
497
+
462
498
return (
463
499
alt .Chart (dat )
464
500
.transform_fold (fold = ["Infected" , "Recovered" ])
465
501
.mark_line ()
466
502
.encode (
467
503
x = alt .X (** x_kwargs ),
468
- y = alt .Y ("value:Q" , title = "Case Volume" ),
504
+ y = alt .Y ("value:Q" , title = "Case Volume" , scale = y_scale ),
469
505
tooltip = ["key:N" , "value:Q" ],
470
506
color = "key:N" ,
471
507
)
472
508
.interactive ()
473
509
)
474
510
475
511
476
- def show_additional_projections (st , alt , charting_func , i , r , as_date : bool = False ):
512
+ def show_additional_projections (
513
+ st ,
514
+ alt ,
515
+ charting_func ,
516
+ i ,
517
+ r ,
518
+ as_date : bool = False ,
519
+ max_y_axis : int = None
520
+ ):
477
521
st .subheader (
478
522
"The number of infected and recovered individuals in the hospital catchment region at any given moment"
479
523
)
480
524
481
- st .altair_chart (charting_func (alt , i , r , as_date = as_date ), use_container_width = True )
525
+ st .altair_chart (charting_func (alt , i , r , as_date = as_date , max_y_axis = max_y_axis ), use_container_width = True )
482
526
483
527
484
528
##########
0 commit comments