Skip to content
Snippets Groups Projects
Commit 5e10c7ff authored by David Schäfer's avatar David Schäfer
Browse files

Merge branch 'ax_plot' into 'develop'

Add option to pas existing axis object to the plot function

See merge request !597
parents 788cd7fb b7e72f87
No related branches found
No related tags found
3 merge requests!685Release 2.4,!684Release 2.4,!597Add option to pas existing axis object to the plot function
Pipeline #141868 passed with stages
in 8 minutes and 16 seconds
......@@ -10,6 +10,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
[List of commits](https://git.ufz.de/rdm-software/saqc/-/compare/v2.2.1...develop)
### Added
- add option to not overwrite existing flags to `concatFlags`
- add option to pass existing axis object to `plot`
### Changed
- Remove all flag value restrictions from the default flagging scheme `FloatTranslator`
- Renamed `TranslationScheme.forward` to `TranslationScheme.toInternal`
......
......@@ -234,6 +234,7 @@ class ToolsMixin:
xscope: Optional[slice] = None,
phaseplot: Optional[str] = None,
store_kwargs: Optional[dict] = None,
ax: mpl.axes.Axes | None = None,
ax_kwargs: Optional[dict] = None,
dfilter: float = FILTER_NONE,
**kwargs,
......@@ -297,7 +298,6 @@ class ToolsMixin:
"""
data, flags = self._data.copy(), self._flags.copy()
interactive = path is None
level = kwargs.get("flag", UNFLAGGED)
if dfilter < np.inf:
......@@ -309,9 +309,8 @@ class ToolsMixin:
if ax_kwargs is None:
ax_kwargs = {}
if interactive:
if not path:
mpl.use(_MPL_DEFAULT_BACKEND)
else:
mpl.use("Agg")
......@@ -324,13 +323,14 @@ class ToolsMixin:
history=history,
xscope=xscope,
phaseplot=phaseplot,
ax=ax,
ax_kwargs=ax_kwargs,
)
if interactive:
if ax is None:
plt.show()
else:
if path:
if store_kwargs.pop("pickle", False):
with open(path, "wb") as f:
pickle.dump(fig, f)
......
......@@ -6,6 +6,8 @@
# -*- coding: utf-8 -*-
from __future__ import annotations
import itertools
from typing import Optional, Union
......@@ -58,11 +60,12 @@ def makeFig(
field: str,
flags: Flags,
level: float,
max_gap: Optional[str] = None,
history: Union[Optional[Literal["valid", "complete"]], list] = "valid",
xscope: Optional[slice] = None,
phaseplot: Optional[str] = None,
ax_kwargs: Optional[dict] = None,
max_gap: str | None = None,
history: Literal["valid", "complete"] | None | list[str] = "valid",
xscope: slice | None = None,
phaseplot: str | None = None,
ax: mpl.axes.Axes | None = None,
ax_kwargs: dict | None = None,
):
"""
Returns a figure object, containing data graph with flag marks for field.
......@@ -152,9 +155,10 @@ def makeFig(
d = _insertBlockingNaNs(d, max_gap)
# figure composition
fig = mpl.pyplot.figure(constrained_layout=True, **FIG_KWARGS)
grid = fig.add_gridspec()
ax = fig.add_subplot(grid[0])
if ax is None:
fig = mpl.pyplot.figure(constrained_layout=True, **FIG_KWARGS)
grid = fig.add_gridspec()
ax = fig.add_subplot(grid[0])
_plotVarWithFlags(
ax,
......@@ -172,7 +176,7 @@ def makeFig(
)
plt.rcParams["font.size"] = default
return fig
return ax.figure
def _plotVarWithFlags(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment