diff --git a/saqc/funcs/tools.py b/saqc/funcs/tools.py index f94d56d103967eee162d767da55f9795093f2599..daa79f2f18df2df1c93cd86d81089563bbc6d222 100644 --- a/saqc/funcs/tools.py +++ b/saqc/funcs/tools.py @@ -261,6 +261,12 @@ def plot( """ Stores or shows a figure object, containing data graph with flag marks for field. + There are two modes, 'interactive' and 'store' mode, wich is determind via the + ``save_path`` keyword. In interactive mode (default) the plot is shown at runtime + and the execution stops until the plot window is closed manually by a user. In + store mode the generated plot is stored to disk and no manually interaction is + needed. + Parameters ---------- data : {pd.DataFrame, dios.DictOfSeries} @@ -273,8 +279,10 @@ def plot( Flags or flagger object save_path : str, default None - Path to the location where the figure shall be stored to. - If ``None`` is passed, plots are not stored and shown interactively instead. + If ``None`` is passed, interactive mode is entered; plots are shown immediatly + and a user need to close them manually before execution continues. + If a filepath is passed instead, store-mode is entered and + the plot is stored unter the passed location. max_gap : str, default None If None, all the points in the data will be connected, resulting in long linear @@ -301,8 +309,9 @@ def plot( removed by later tests fig_kwargs : dict, default None - Keyword arguments controlling figure generation. ``None`` defaults to - ``{"figsize": (16, 9)}``. + Keyword arguments controlling figure generation. In interactive mode, + ``None`` defaults to ``{"figsize": (16, 9)}`` to ensure a proper figure size, + in store-mode ``None`` defaults to a empty dictionary. save_kwargs : dict, default {} Keywords to be passed on to the ``matplotlib.pyplot.savefig`` method, handling @@ -347,8 +356,12 @@ def plot( if interactive: mpl.use(_MPL_DEFAULT_BACKEND) + else: mpl.use("Agg") + # ensure a proper size in stored plot + if fig_kwargs is None: + fig_kwargs = {"figsize": (16, 9)} fig = makeFig( data=data, diff --git a/saqc/lib/plotting.py b/saqc/lib/plotting.py index 1659ba9daab0a851379f0a3cbac6c6d768a450af..bd5ef88ce607bc6a0f30e08ca3c5dbc57fc3fef4 100644 --- a/saqc/lib/plotting.py +++ b/saqc/lib/plotting.py @@ -118,7 +118,7 @@ def makeFig( if plot_kwargs is None: plot_kwargs = {"history": False} if fig_kwargs is None: - fig_kwargs = {"figsize": (16, 9)} + fig_kwargs = {} if stats_dict is None: stats_dict = {}