22scenarios (scenario_impact_of_healthsystem.py)"""
33
44import argparse
5+ import textwrap
56from pathlib import Path
67from typing import Tuple
78
@@ -86,7 +87,7 @@ def find_difference_relative_to_comparison(_ser: pd.Series,
8687 .drop (columns = ([comparison ] if drop_comparison else [])) \
8788 .stack ()
8889
89- def do_bar_plot_with_ci (_df , annotations = None ):
90+ def do_bar_plot_with_ci (_df , annotations = None , xticklabels_horizontal_and_wrapped = False ):
9091 """Make a vertical bar plot for each row of _df, using the columns to identify the height of the bar and the
9192 extent of the error bar."""
9293 yerr = np .array ([
@@ -110,7 +111,12 @@ def do_bar_plot_with_ci(_df, annotations=None):
110111 for xpos , ypos , text in zip (xticks .keys (), _df ['upper' ].values , annotations ):
111112 ax .text (xpos , ypos * 1.05 , text , horizontalalignment = 'center' )
112113 ax .set_xticks (list (xticks .keys ()))
113- ax .set_xticklabels (list (xticks .values ()), rotation = 90 )
114+ if not xticklabels_horizontal_and_wrapped :
115+ # xticklabels will be vertical and not wrapped
116+ ax .set_xticklabels (list (xticks .values ()), rotation = 90 )
117+ else :
118+ wrapped_labs = ["\n " .join (textwrap .wrap (_lab , 20 )) for _lab in xticks .values ()]
119+ ax .set_xticklabels (wrapped_labs )
114120 ax .grid (axis = "y" )
115121 ax .spines ['top' ].set_visible (False )
116122 ax .spines ['right' ].set_visible (False )
@@ -267,9 +273,27 @@ def rename_scenarios_in_index(ser: pd.Series) -> pd.Series:
267273 ]
268274 )
269275 ax .set_title (name_of_plot )
270- ax .set_ylim (0 , 14 )
271- ax .set_yticks (np .arange (0 , 16 , 2 ))
272- # ax.set_xticklabels(list(ax.get_xticklabels()), rotation=0)
276+ ax .set_ylim (0 , 16 )
277+ ax .set_yticks (np .arange (0 , 18 , 2 ))
278+ ax .set_ylabel ('Additional DALYS Averted \n (Millions)' )
279+ fig .tight_layout ()
280+ fig .savefig (make_graph_file_name (name_of_plot .replace (' ' , '_' ).replace (',' , '' )))
281+ fig .show ()
282+ plt .close (fig )
283+
284+ # DALYS (with xtickabels horizontal and wrapped)
285+ name_of_plot = f'Additional DALYs Averted vs Status Quo, { target_period ()} '
286+ fig , ax = do_bar_plot_with_ci (
287+ (num_dalys_averted / 1e6 ).clip (lower = 0.0 ),
288+ annotations = [
289+ f"{ round (row ['mean' ], 1 )} ({ round (row ['lower' ], 1 )} -{ round (row ['upper' ], 1 )} ) %"
290+ for _ , row in pc_dalys_averted .clip (lower = 0.0 ).iterrows ()
291+ ],
292+ xticklabels_horizontal_and_wrapped = True ,
293+ )
294+ ax .set_title (name_of_plot )
295+ ax .set_ylim (0 , 16 )
296+ ax .set_yticks (np .arange (0 , 18 , 2 ))
273297 ax .set_ylabel ('Additional DALYS Averted \n (Millions)' )
274298 fig .tight_layout ()
275299 fig .savefig (make_graph_file_name (name_of_plot .replace (' ' , '_' ).replace (',' , '' )))
0 commit comments