bucky.viz.plot
¶
Creates line plots with confidence intervals at the ADM0, ADM1, or ADM2 level.
Module Contents¶
Functions¶
|
Adds simulation data for requested column to initialized matplotlib axis object. |
|
Add historical data for requested column and area to initialized matplotlib axis object. |
|
Determine plot title for a given area based on adm code and lookup table. |
|
Main entrypoint. |
|
Wrapper function around plot. Creates plots, aggregating data if necessary. |
|
Given a dataframe and a key, creates plots with requested columns. |
|
Check that historical data has the correct date range and requested number of data points. |
Attributes¶
- bucky.viz.plot.default_plot_cols = ['daily_reported_cases', 'daily_deaths']¶
- bucky.viz.plot.add_col_data_to_plot(axis, col, sim_data, quantiles_list)[source]¶
Adds simulation data for requested column to initialized matplotlib axis object.
- Parameters
axis (
matplotlib.axes.Axes
) – Previously initialized axis objectcol (
str
) – Column to add to plotsim_data (
pandas.DataFrame
) – Area simulation dataquantiles_list (
list
offloat
, orNone
) – List of quantiles to plot. If None, will plot all available quantiles in data.
- Returns
axis – Modified axis object with added data
- Return type
- bucky.viz.plot.add_hist_data_to_plot(axis, historical_data, adm_key, adm_value, col, sim_max_date)[source]¶
Add historical data for requested column and area to initialized matplotlib axis object.
- Parameters
axis (
matplotlib.axes.Axes
) – Previously initialized axis objecthistorical_data (
pandas.DataFrame
) – Dataframe of historical dataadm_key (
str
) – Admin key to use to relate simulation data and geographic areasadm_value (
int
) – Admin code value for areacol (
str
) – Column to add to plotsim_max_date (
pandas.Timestamp
) – Latest date in simulation data
- Returns
axis – Modified axis object with added data
- Return type
- bucky.viz.plot.get_plot_title(l_table, adm_key, adm_value)[source]¶
Determine plot title for a given area based on adm code and lookup table.
For ADM0 and ADM1 plots, uses names. For ADM2 plots, the ADM1 name is included in addition to the ADM2 name.
- Parameters
l_table (
pandas.DataFrame
) – Dataframe containing information relating different geographic areasadm_key (
str
) – Admin level keyadm_value (
int
) – Admin code value for area
- Returns
plot_title – Formatted string to use for plot title
- Return type
- bucky.viz.plot.make_plots(adm_levels, input_directory, output_directory, lookup_df, plot_hist, plot_columns, quantiles, window_size, end_date, hist_file, min_hist_points, admin1=None, hist_start=None)[source]¶
Wrapper function around plot. Creates plots, aggregating data if necessary.
- Parameters
adm_levels (
list
ofstr
) – List of ADM levels to make plots forinput_directory (
str
) – Location of simulation dataoutput_directory (
str
) – Parent directory to place created plots.lookup_df (
pandas.DataFrame
) – Lookup table for geographic mapping informationplot_hist (
bool
) – If True, will plot historical data.plot_columns (
list
ofstr
) – List of columns to plot from data.quantiles (
list
offloat
, orNone
) – List of quantiles to plot. If None, will plot all available quantiles in data.window_size (
int
) – Size of window (in days) to apply to historical data.end_date (
str
) – Plot data until this date. Must be formatted as YYYY-MM-DD. If None, uses last date in simulation.hist_file (
str
) – Path to historical data file. If None, uses either CSSE or Covid Tracking data depending on columns requested.min_hist_points (
int
) – Minimum number of historical data points to plot.admin1 (
list
ofstr
, orNone
) – List of admin1 values to make plots for. If None, a plot will be created for every unique admin1 values. Otherwise, plots are only made for those requested.hist_start (
str
, orNone
) – Plot historical data from this point (formatted as YYYY-MM-DD). If None, aligns with simulation start date.
- bucky.viz.plot.plot(out_dir, lookup_df, key, sim_data, hist_data, plot_columns, quantiles)[source]¶
Given a dataframe and a key, creates plots with requested columns.
For example, a pandas.DataFrame with state-level data would create a plot for each unique state. Simulation data is plotted as a line with shaded confidence intervals. Historical data is added as scatter points if requested.
- Parameters
out_dir (
str
) – Location to place created plots.lookup_df (
pandas.DataFrame
) – Dataframe containing information relating different geographic areaskey (
str
) – Key to use to relate simulation data and geographic areas. Must appear in lookup and simulation data (and historical data if applicable)sim_data (
pandas.DataFrame
) – Simulation data to plothist_data (
pandas.DataFrame
) – Historical data to add to plotquantiles (
list
offloat
, orNone
) – List of quantiles to plot. If None, will plot all available quantiles in data.
- bucky.viz.plot.preprocess_historical_dates(historical_data, hist_start_date, plot_start, plot_end, min_data_points)[source]¶
Check that historical data has the correct date range and requested number of data points.
- Parameters
historical_data (
pandas.DataFrame
) – Dataframe with requested historical datahist_start_date (
str
orNone
) – Plot historical data from this point (formatted as YYYY-MM-DD). If None, aligns with simulation start date.plot_start (
pandas.Timestamp
) – Earliest date appearing in simulation dataplot_end (
pandas.Timestamp
) – Latest date appearing in simulation datamin_data_points (
int
) – Minimum number of historical data points to plot
- Returns
historical_data – Historical data with the correct date range and number of points
- Return type