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 ...@@ -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) [List of commits](https://git.ufz.de/rdm-software/saqc/-/compare/v2.2.1...develop)
### Added ### Added
- add option to not overwrite existing flags to `concatFlags` - add option to not overwrite existing flags to `concatFlags`
- add option to pass existing axis object to `plot`
### Changed ### Changed
- Remove all flag value restrictions from the default flagging scheme `FloatTranslator` - Remove all flag value restrictions from the default flagging scheme `FloatTranslator`
- Renamed `TranslationScheme.forward` to `TranslationScheme.toInternal` - Renamed `TranslationScheme.forward` to `TranslationScheme.toInternal`
......
...@@ -234,6 +234,7 @@ class ToolsMixin: ...@@ -234,6 +234,7 @@ class ToolsMixin:
xscope: Optional[slice] = None, xscope: Optional[slice] = None,
phaseplot: Optional[str] = None, phaseplot: Optional[str] = None,
store_kwargs: Optional[dict] = None, store_kwargs: Optional[dict] = None,
ax: mpl.axes.Axes | None = None,
ax_kwargs: Optional[dict] = None, ax_kwargs: Optional[dict] = None,
dfilter: float = FILTER_NONE, dfilter: float = FILTER_NONE,
**kwargs, **kwargs,
...@@ -297,7 +298,6 @@ class ToolsMixin: ...@@ -297,7 +298,6 @@ class ToolsMixin:
""" """
data, flags = self._data.copy(), self._flags.copy() data, flags = self._data.copy(), self._flags.copy()
interactive = path is None
level = kwargs.get("flag", UNFLAGGED) level = kwargs.get("flag", UNFLAGGED)
if dfilter < np.inf: if dfilter < np.inf:
...@@ -309,9 +309,8 @@ class ToolsMixin: ...@@ -309,9 +309,8 @@ class ToolsMixin:
if ax_kwargs is None: if ax_kwargs is None:
ax_kwargs = {} ax_kwargs = {}
if interactive: if not path:
mpl.use(_MPL_DEFAULT_BACKEND) mpl.use(_MPL_DEFAULT_BACKEND)
else: else:
mpl.use("Agg") mpl.use("Agg")
...@@ -324,13 +323,14 @@ class ToolsMixin: ...@@ -324,13 +323,14 @@ class ToolsMixin:
history=history, history=history,
xscope=xscope, xscope=xscope,
phaseplot=phaseplot, phaseplot=phaseplot,
ax=ax,
ax_kwargs=ax_kwargs, ax_kwargs=ax_kwargs,
) )
if interactive: if ax is None:
plt.show() plt.show()
else: if path:
if store_kwargs.pop("pickle", False): if store_kwargs.pop("pickle", False):
with open(path, "wb") as f: with open(path, "wb") as f:
pickle.dump(fig, f) pickle.dump(fig, f)
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import annotations
import itertools import itertools
from typing import Optional, Union from typing import Optional, Union
...@@ -58,11 +60,12 @@ def makeFig( ...@@ -58,11 +60,12 @@ def makeFig(
field: str, field: str,
flags: Flags, flags: Flags,
level: float, level: float,
max_gap: Optional[str] = None, max_gap: str | None = None,
history: Union[Optional[Literal["valid", "complete"]], list] = "valid", history: Literal["valid", "complete"] | None | list[str] = "valid",
xscope: Optional[slice] = None, xscope: slice | None = None,
phaseplot: Optional[str] = None, phaseplot: str | None = None,
ax_kwargs: Optional[dict] = None, ax: mpl.axes.Axes | None = None,
ax_kwargs: dict | None = None,
): ):
""" """
Returns a figure object, containing data graph with flag marks for field. Returns a figure object, containing data graph with flag marks for field.
...@@ -152,9 +155,10 @@ def makeFig( ...@@ -152,9 +155,10 @@ def makeFig(
d = _insertBlockingNaNs(d, max_gap) d = _insertBlockingNaNs(d, max_gap)
# figure composition # figure composition
fig = mpl.pyplot.figure(constrained_layout=True, **FIG_KWARGS) if ax is None:
grid = fig.add_gridspec() fig = mpl.pyplot.figure(constrained_layout=True, **FIG_KWARGS)
ax = fig.add_subplot(grid[0]) grid = fig.add_gridspec()
ax = fig.add_subplot(grid[0])
_plotVarWithFlags( _plotVarWithFlags(
ax, ax,
...@@ -172,7 +176,7 @@ def makeFig( ...@@ -172,7 +176,7 @@ def makeFig(
) )
plt.rcParams["font.size"] = default plt.rcParams["font.size"] = default
return fig return ax.figure
def _plotVarWithFlags( 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