covsirphy.visualization package

covsirphy.visualization.bar_plot module

class BarPlot(filename=None, bbox_inches='tight', **kwargs)[source]

Bases: VisualizeBase

Create a bar plot.

Parameters:
  • filename (str or None) – filename to save the figure or None (display)

  • bbox_inches (str) – bounding box in inches when creating the figure

  • kwargs – the other arguments of matplotlib.pyplot.savefig()

line(v=None, h=None, color='black', linestyle=':')[source]

Show vertical/horizontal lines.

Parameters:
  • v (list[int/float] or None) – list of x values of vertical lines or None

  • h (list[int/float] or None) – list of y values of horizontal lines or None

  • color (str) – color of the line

  • linestyle (str) – linestyle

plot(data, vertical=True, colormap=None, color_dict=None, **kwargs)[source]

Create bar plot.

Parameters:
x_axis(xlabel=None)[source]

Set x axis.

Parameters:

xlabel (str or None) – x-label

y_axis(ylabel='Cases', y_logscale=False, ylim=(0, None), math_scale=True, y_integer=False)[source]

Set x axis.

Parameters:
  • ylabel (str or None) – y-label

  • y_logscale (bool) – whether use log-scale in y-axis or not

  • ylim (tuple(int or float, int or float)) – limit of y domain

  • math_scale (bool) – whether use LaTEX or not in y-label

  • y_integer (bool) – whether force to show the values as integer or not

Note

If None is included in ylim, the values will be automatically determined by Matplotlib

bar_plot(df, title=None, filename=None, show_legend=True, **kwargs)[source]

Wrapper function: show chronological change of the data.

Parameters:
  • data (pandas.DataFrame or pandas.Series) –

    data to show Index

    Date (pandas.Timestamp)

    Columns

    variables to show

  • title (str) – title of the figure

  • filename (str or None) – filename to save the figure or None (display)

  • show_legend (bool) – whether show legend or not

  • kwargs – keyword arguments of the following classes and methods. - covsirphy.BarPlot() and its methods, - matplotlib.pyplot.savefig(), matplotlib.pyplot.legend(), - pandas.DataFrame.plot()

covsirphy.visualization.compare_plot module

class ComparePlot(filename=None, bbox_inches='tight', **kwargs)[source]

Bases: VisualizeBase

Compare two groups with specified variables.

Parameters:
  • filename (str or None) – filename to save the figure or None (display)

  • bbox_inches (str) – bounding box in inches when creating the figure

  • kwargs – the other arguments of matplotlib.pyplot.savefig()

plot(data, variables, groups)[source]

Compare two groups with specified variables.

Parameters:
  • data (pandas.DataFrame) –

    data to show Index

    x values

    Columns

    y variables to show, “{variable}_{group}” for all combinations of variables and groups

  • variables (list[str]) – variables to compare

  • groups (list[str]) – the first group name and the second group name

compare_plot(df, variables, groups, filename=None, **kwargs)[source]

Wrapper function: show chronological change of the data.

Parameters:
  • df (pandas.DataFrame) –

    data to show Index

    x values

    Columns

    y variables to show, “{variable}_{group}” for all combinations of variables and groups

  • variables (list[str]) – variables to compare

  • groups (list[str]) – the first group name and the second group name

  • filename (str or None) – filename to save the figure or None (display)

  • kwargs – keyword arguments of the following classes and methods. - matplotlib.pyplot.savefig() - matplotlib.pyplot.legend()

covsirphy.visualization.line_plot module

class LinePlot(filename=None, bbox_inches='tight', **kwargs)[source]

Bases: VisualizeBase

Create a line plot.

Parameters:
  • filename (str or None) – filename to save the figure or None (display)

  • bbox_inches (str) – bounding box in inches when creating the figure

  • kwargs – the other arguments of matplotlib.pyplot.savefig()

line(v=None, h=None, color='black', linestyle=':')[source]

Show vertical/horizontal lines.

Parameters:
  • v (list/tuple[int/float] or None) – list of x values of vertical lines or None

  • h (list/tuple[int/float] or None) – list of y values of horizontal lines or None

  • color (str) – color of the line

  • linestyle (str) – linestyle

plot(data, colormap=None, color_dict=None, **kwargs)[source]

Plot chronological change of the data.

Parameters:
x_axis(xlabel=None, x_logscale=False, xlim=(None, None))[source]

Set x axis.

Parameters:
  • xlabel (str or None) – x-label

  • x_logscale (bool) – whether use log-scale in x-axis or not

  • xlim (tuple(int or float, int or float)) – limit of x domain

Note

If None is included in xlim, the values will be automatically determined by Matplotlib

y_axis(ylabel='Cases', y_logscale=False, ylim=(0, None), math_scale=True, y_integer=False)[source]

Set x axis.

Parameters:
  • ylabel (str or None) – y-label

  • y_logscale (bool) – whether use log-scale in y-axis or not

  • ylim (tuple(int or float, int or float)) – limit of y domain

  • math_scale (bool) – whether use LaTEX or not in y-label

  • y_integer (bool) – whether force to show the values as integer or not

Note

If None is included in ylim, the values will be automatically determined by Matplotlib

line_plot(df, title=None, filename=None, show_legend=True, **kwargs)[source]

Wrapper function: show chronological change of the data.

Parameters:
  • data (pandas.DataFrame or pandas.Series) –

    data to show Index

    Date (pandas.Timestamp)

    Columns

    variables to show

  • title (str) – title of the figure

  • filename (str or None) – filename to save the figure or None (display)

  • show_legend (bool) – whether show legend or not

  • kwargs – keyword arguments of the following classes and methods. - covsirphy.LinePlot() and its methods, - matplotlib.pyplot.savefig(), matplotlib.pyplot.legend(), - pandas.DataFrame.plot()

covsirphy.visualization.scatter_plot module

class ScatterPlot(filename=None, bbox_inches='tight', **kwargs)[source]

Bases: LinePlot

Create a scatter plot.

Parameters:
  • filename (str or None) – filename to save the figure or None (display)

  • bbox_inches (str) – bounding box in inches when creating the figure

  • kwargs – the other arguments of matplotlib.pyplot.savefig()

legend(**kwargs)[source]

ScatterPlot.legend() is not implemented.

legend_hide()[source]

ScatterPlot.legend_hide() is not implemented.

line_straight(p1=None, p2=None, color='black', linestyle=':')[source]

Connect the points with a straight line.

Parameters:
  • p1 (tuple(int or float, int or float) or None) – (x, y) of the first point or None (min values)

  • p2 (tuple(int or float, int or float) or None) – (x, y) of the second point or None (max values)

  • color (str) – color of the line

  • linestyle (str) – linestyle

Note

The same line will be show when p1 and p2 is reordered.

plot(data, colormap=None, color_dict=None, **kwargs)[source]

Plot chronological change of the data.

Parameters:
scatter_plot(df, title=None, filename=None, **kwargs)[source]

Wrapper function: show chronological change of the data.

Parameters:
  • data (pandas.DataFrame) –

    data to show Index

    reset index

    Columns

    x (int or float): x values y (int or float): y values

  • title (str) – title of the figure

  • filename (str or None) – filename to save the figure or None (display)

  • kwargs – keyword arguments of the following classes and methods. - covsirphy.ScatterPlot() and its methods, - matplotlib.pyplot.savefig(), matplotlib.pyplot.legend(), - pandas.DataFrame.plot()

covsirphy.visualization.vbase module

class VisualizeBase(filename=None, bbox_inches='tight', **kwargs)[source]

Bases: Term

Base class for visualization.

Parameters:
  • filename (str or None) – filename to save the figure or None (display)

  • bbox_inches (str) – bounding box in inches when creating the figure

  • kwargs – the other arguments of matplotlib.pyplot.savefig

property ax

axis

Type:

matplotlib.axis

legend(bbox_to_anchor=(0.5, -0.2), bbox_loc='lower center', ncol=None, **kwargs)[source]

Set legend.

Parameters:
  • bbox_to_anchor (tuple(int or float, int or float)) – distance of legend and plot

  • bbox_loc (str) – location of legend

  • ncol (int or None) – the number of columns that the legend has

  • kwargs – keyword arguments of matplotlib.pyplot.legend()

legend_hide()[source]

Hide legend.

plot()[source]

Method for plotting. This will be defined in child classes.

Raises:

NotImplementedError – not implemented

tick_params(**kwargs)[source]

Directly calling matplotlib.pyplot.tick_params, change the appearance of ticks, tick labels and grid lines.

Parameters:

kwargs – arguments of matplotlib.pyplot.tick_params

property title

title of the figure

Type:

str

find_args(func_list, **kwargs)[source]

Find values of enabled arguments of the function from the keyword arguments.

Parameters:
  • func_list (list[function] or function) – target function

  • kwargs – keyword arguments

Returns:

dict – dictionary of enabled arguments