2
2
scenarios (scenario_impact_of_healthsystem.py)"""
3
3
4
4
import argparse
5
+ import textwrap
5
6
from pathlib import Path
6
7
from typing import Tuple
7
8
@@ -86,7 +87,7 @@ def find_difference_relative_to_comparison(_ser: pd.Series,
86
87
.drop (columns = ([comparison ] if drop_comparison else [])) \
87
88
.stack ()
88
89
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 ):
90
91
"""Make a vertical bar plot for each row of _df, using the columns to identify the height of the bar and the
91
92
extent of the error bar."""
92
93
yerr = np .array ([
@@ -110,7 +111,12 @@ def do_bar_plot_with_ci(_df, annotations=None):
110
111
for xpos , ypos , text in zip (xticks .keys (), _df ['upper' ].values , annotations ):
111
112
ax .text (xpos , ypos * 1.05 , text , horizontalalignment = 'center' )
112
113
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 )
114
120
ax .grid (axis = "y" )
115
121
ax .spines ['top' ].set_visible (False )
116
122
ax .spines ['right' ].set_visible (False )
@@ -267,9 +273,27 @@ def rename_scenarios_in_index(ser: pd.Series) -> pd.Series:
267
273
]
268
274
)
269
275
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 ))
273
297
ax .set_ylabel ('Additional DALYS Averted \n (Millions)' )
274
298
fig .tight_layout ()
275
299
fig .savefig (make_graph_file_name (name_of_plot .replace (' ' , '_' ).replace (',' , '' )))
0 commit comments