xy_plot
create_common_x_values(a_old, b_old)
Matplotlib needs the x-values to be the same for different (x,y) lines being plotted. This method creates a new version of each set of values.
Source code in emodpy_hiv/plotting/xy_plot.py
fill_in_y_values(x_old, y_old, x_new)
Since matplotlib needs the lines/curves to have the same X-values, we need to find the associated Y-values when we add the new X-values. This method uses linear interpolation to find the values between points.
Source code in emodpy_hiv/plotting/xy_plot.py
xy_plot(img_dir, df, title_1, title_2, x_axis_name='Years', y_axis_name='', expected_df=None, fraction_of_total=False, show_legend=True, show_markers=True, min_x=None, max_x=None, min_y=None, max_y=None, x_axis_as_log_scale=False, y_axis_as_log_scale=False)
Create a plot using the give dataframe, 'df', with all of the appropriate labels. The index of the dataframe will be used for the X-axis and the lines or curves will be for each column of the dataframe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_dir
|
(str, required)
|
Directory to save the images. If None, the images will not be saved and a window will be opened. |
required |
df
|
(DataFrame, required)
|
A dataframe where the index will be used for the X-values and each column will get a separate line/curve. The name of the column will be used in the legend. |
required |
title_1
|
(str, required)
|
This will be the top line text on the plot. |
required |
title_2
|
(str, required)
|
This will be the second line of text ohe plot. |
required |
x_axis_name
|
str
|
This is the label used to indicate what the X-axis values are. |
'Years'
|
y_axis_name
|
str
|
This is the label used to indicate what the Y-axis values are. |
''
|
expected_df
|
DataFame
|
This dataframe is expected to have a similar format to the 'df' dataframe. The index of the dataframe is the X-values and should similar to that of 'df'. The columns are the Y-values and each column creates a separate line/curve. However, these will be plotted in black, the markers a little larger, and on top of the lines from the 'df'. |
None
|
fraction_of_total
|
bool
|
If true, the columns of each dataframe are summed and divided by this sum to create a fraction of the total. |
False
|
show_legend
|
bool
|
If True a legend will be placed on the right side of the plot, but beware that long column names can make the plot space very small. |
True
|
show_markers
|
bool
|
if True the lines will have markers at each data point. |
True
|
min_x
|
float
|
If provided the plot will have a fixed minimum value for the X-axis independent of the data. When not provided, matplotlib determines the minimum based on the data. |
None
|
max_x
|
float
|
If provided the plot will have a fixed maximum value for the X-axis independent of the data. When not provided, matplotlib determines the minimum based on the data. |
None
|
min_y
|
float
|
If provided the plot will have a fixed minimum value for the Y-axis independent of the data. When not provided, matplotlib determines the minimum based on the data. |
None
|
max_y
|
float
|
If provided the plot will have a fixed maximum value for the Y-axis independent of the data. When not provided, matplotlib determines the minimum based on the data. |
None
|
x_axis_as_log_scale
|
bool
|
If True, the X-axis is assumed to be logrithmic. |
False
|
y_axis_as_log_scale
|
bool
|
If True, the Y-axis is assumed to be logrithmic. |
False
|
Returns:
Source code in emodpy_hiv/plotting/xy_plot.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |