mlair.plotting.abstract_plot_class

Abstract plot class that should be used for preprocessing and postprocessing plots.

Module Contents

Classes

AbstractPlotClass

Abstract class for all plotting routines to unify plot workflow.

Attributes

__author__

__date__

mlair.plotting.abstract_plot_class.__author__ = Lukas Leufen
mlair.plotting.abstract_plot_class.__date__ = 2021-04-13
class mlair.plotting.abstract_plot_class.AbstractPlotClass(plot_folder, plot_name, resolution=500, rc_params=None)

Abstract class for all plotting routines to unify plot workflow.

Each inheritance requires a _plot method. Create a plot class like:

class MyCustomPlot(AbstractPlotClass):

    def __init__(self, plot_folder, *args, **kwargs):
        super().__init__(plot_folder, "custom_plot_name")
        self._data = self._prepare_data(*args, **kwargs)
        self._plot(*args, **kwargs)
        self._save()

    def _prepare_data(*args, **kwargs):
        <your custom data preparation>
        return data

    def _plot(*args, **kwargs):
        <your custom plotting without saving>

The save method is already implemented in the AbstractPlotClass. If special saving is required (e.g. if you are using pdfpages), you need to overwrite it. Plots are saved as .pdf with a resolution of 500dpi per default (can be set in super class initialisation).

Methods like the shown _prepare_data() are optional. The only method required to implement is _plot.

If you want to add a time tracking module, just add the TimeTrackingWrapper as decorator around your custom plot class. It will log the spent time if you call your plotting without saving the returned object.

@TimeTrackingWrapper
class MyCustomPlot(AbstractPlotClass):
    pass

Let’s assume it takes a while to create this very special plot.

>>> MyCustomPlot()
INFO: MyCustomPlot finished after 00:00:11 (hh:mm:ss)
__del__(self)
abstract _plot(self, *args)

Abstract plot class needs to be implemented in inheritance.

_save(self, **kwargs)

Store plot locally. Name of and path to plot need to be set on initialisation.

_update_rc_params(self)
static _get_sampling(sampling, pos=1)
static get_dataset_colors()

Standard colors used for train-, val-, and test-sets during postprocessing