hifis_surveyval.plotting package

Submodules

hifis_surveyval.plotting.matplotlib_plotter module

This module provides functionality to plot survey data.

This module is called by survey analysis scripts and is a helper module which processes pandas data-frames as input and transforms them into informative plots. The actual plotting is done by utilizing a separate plotting library called matplotlib.

class hifis_surveyval.plotting.matplotlib_plotter.MatplotlibPlotter(output_format: hifis_surveyval.plotting.supported_output_format.SupportedOutputFormat, output_path: pathlib.Path)[source]

Bases: hifis_surveyval.plotting.plotter.Plotter

Provides standardized plotting functionalities with matplotlib.

plot_bar_chart(data_frame: <MagicMock id='140134835176736'>, plot_file_name: str = '', show_legend: bool = True, show_value_labels: bool = True, round_value_labels_to_decimals: int = 0, **kwargs) None[source]

Plot given data-frame as a (stacked) bar chart.

A pandas DataFrame is used as input data from which a (stacked) bar chart is generated. This DataFrame need be structured in a particular way. The actual data values are taken column by column and plotted as bars for each index entry. In case of a normal bar chart this means each sequence of bars / column is put next to each other while each sequence is grouped by the series / rows and labeled accordingly in the legend. By contrast in case of a stacked bar chart each sequence of bars / column is stacked on top of the previous instead of put next to each other and labeled accordingly in the legend. The index names are used to label the ticks along the x-axis, while the column names are used as labels in the legend.

Args:
data_frame (DataFrame):

All data needed for this function to plot a stacked bar chart is encapsulated in this DataFrame.

plot_file_name (str):

Optional file name which is used to store the plot to a file. If this argument is an empty string (Default) for this argument, a suitable file name is auto-generated.

show_legend (bool):

Used to control whether a legend is included in the plot or not. (Default: True)

show_value_labels (bool):

Enable or disable labels to show the values of each bar. ( Default: True)

round_value_labels_to_decimals (int):

Round label values to the number of decimals. (Default: 0)

**kwargs:
stacked (bool):

Prompts the generation of a stacked bar chart instead on bars being grouped side-by-side.

plot_title (str):

The title text for the plot. (Default: “”)

x_axis_label (str):

The label for the x-axis. Default: “”)

x_label_rotation (int):

Allows to rotate the x-axis labels for better readability. Value is given in degrees. (Default: 0)

y_axis_label (str):

The label for the y-axis. Default: “”)

legend_location (str):

Specifies positioning of the plot’s legend. (Default: “best”) See Also: pandas.Axis.legend(loc)

legend_anchor (BboxBase):

Allows to specify an anchor point for the plot’s legend ( Default: None) See Also: pandas.Axis.legend(bbox_to_anchor)

ylim (Set[float]):

Allows to specify the maximum and minimum values of the y axis (Default: None) See Also: matplotlib.axes.Axes.set_ylim

figure_size (Tuple[float]):

This tuple indicates the aspect ratio in terms of the figure width and height of an image to plot. (Default: The figure is auto-sized if the figure size is not given.)

plot_box_chart(data_frame: Optional[<MagicMock id='140134835176736'>] = None, data_frames: Optional[List[<MagicMock id='140134835176736'>]] = None, plot_file_name: str = '', **kwargs) None[source]

Generate a box chart from the provided data.

Each column in the frame corresponds to one box with whiskers.

Args:
data_frame (Optional[DataFrame]):

A singular data frame. Syntactic sugar for using data_frame=x instead of data_frames=[x].

data_frames (List[DataFrame]):

A list of data frames. The columns with the same column index across all the frames are grouped together.

plot_file_name (str):

Optional file name which is used to store the plot to a file. If this argument is an empty string (Default) for this argument, a suitable file name is auto-generated.

**kwargs:
plot_title (str):

The title text for the plot. (Default: “”)

x_axis_label (str):

The label for the x-axis. Default: “”)

x_label_rotation (int):

Allows to rotate the x-axis labels for better readability. Value is given in degrees. (Default: 0)

y_axis_label (str):

The label for the y-axis. Default: “”)

figure_size (Tuple[float]):

This tuple indicates the aspect ratio in terms of the figure width and height of an image to plot. (Default: The figure is auto-sized if the figure size is not given.)

plot_matrix_chart(data_frame: <MagicMock id='140134835176736'>, plot_file_name: str = '', invert_colors: bool = False, value_label_decimals: int = 2, **kwargs) None[source]

Plot given data frame as matrix chart.

Args:
data_frame (DataFrame):

The data frame to plot.

plot_file_name (str):

(Optional) The file name stem for the output file.

invert_colors (bool):

(Optional) Use an inverted color scheme for plotting. This is recommended for plotting data that represents the absence of something. Defaults to False.

value_label_decimals (int):

Round label values to the number of decimals. (Default: 2)

**kwargs:
plot_title (str):

The title text for the plot. (Dafault: “”)

x_axis_label (str):

The label for the x-axis. Default: “”)

x_label_rotation (int):

Allows to rotate the x-axis labels for better readability. Value is given in degrees. (Default: 0)

y_axis_label (str):

The label for the y-axis. Default: “”)

figure_size (Tuple[float]):

This tuple indicates the aspect ratio in terms of the figure width and height of an image to plot. (Default: The figure is auto-sized if the figure size is not given.)

hifis_surveyval.plotting.plotter module

This module provides a framework for plotters.

class hifis_surveyval.plotting.plotter.Plotter(output_format: hifis_surveyval.plotting.supported_output_format.SupportedOutputFormat, output_path: pathlib.Path)[source]

Bases: abc.ABC

Base class to derive plotters from.

__init__(output_format: hifis_surveyval.plotting.supported_output_format.SupportedOutputFormat, output_path: pathlib.Path) None[source]

Initialize a plotter.

Args:

output_format (SupportedOutputFormat): Supported output format. output_path (Path): Path to the output folder.

hifis_surveyval.plotting.supported_output_format module

This module provides a way of handling output formats for plotters.

class hifis_surveyval.plotting.supported_output_format.SupportedOutputFormat(value)[source]

Bases: enum.Enum

An abstraction of the supported output formats for generated images.

PDF = 2
PNG = 3
SCREEN = 1
SVG = 4
classmethod from_str(enum_entry: str) enum.Enum[source]

Generate an enum object from a string.

Args:
enum_entry (str): String to be converted into another string

representing a supported output format.

Returns:

Enum: Enumeration entry that has been selected.

Raises:
NotImplementedError: Exception thrown if output format is not

supported.

classmethod list() Set[source]

Generate a set listing the supported output formats.

Returns:

Set: Set of supported output formats.

Module contents

This package provides plotting functionalities.