-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added plot_gemiddeldgetij function * improved timedelta formatting and added optional n-hourly ticks * add test for plot_gemiddeldgetij
- Loading branch information
1 parent
9b9bacc
commit 6105b96
Showing
5 changed files
with
184 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,49 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import numpy as np | ||
from matplotlib.ticker import Formatter | ||
|
||
|
||
def raise_extremes_with_aggers(df_ext): | ||
# TODO: alternatively we can convert 12345 to 12 here | ||
if len(df_ext["HWLWcode"].drop_duplicates()) != 2: | ||
raise ValueError("df_ext should only contain extremes (HWLWcode 1/2), " | ||
"but it also contains aggers (HWLWcode 3/4/5). " | ||
"You can convert with `hatyan.calc_HWLW12345to12()`") | ||
|
||
# TODO: create pandas issue suggesting this improvement | ||
class TimeSeries_TimedeltaFormatter_improved(Formatter): | ||
""" | ||
Formats the ticks along an axis controlled by a :class:`TimedeltaIndex`. | ||
based on pandas.plotting._matplotlib.converter.TimeSeries_TimedeltaFormatter | ||
""" | ||
|
||
@staticmethod | ||
def format_timedelta_ticks(x, pos, n_decimals: int) -> str: | ||
""" | ||
Convert seconds to 'D days HH:MM:SS.F' | ||
""" | ||
if x < 0: | ||
negative = True | ||
x = np.abs(x) | ||
else: | ||
negative = False | ||
s, ns = divmod(x, 10**9) | ||
m, s = divmod(s, 60) | ||
h, m = divmod(m, 60) | ||
d, h = divmod(h, 24) | ||
decimals = int(ns * 10 ** (n_decimals - 9)) | ||
s = f"{int(h):02d}:{int(m):02d}:{int(s):02d}" | ||
if n_decimals > 0: | ||
s += f".{decimals:0{n_decimals}d}" | ||
if d != 0: | ||
s = f"{int(d):d} days {s}" | ||
if negative: | ||
s = '-'+s | ||
return s | ||
|
||
def __call__(self, x, pos: int = 0) -> str: | ||
(vmin, vmax) = tuple(self.axis.get_view_interval()) | ||
n_decimals = min(int(np.ceil(np.log10(100 * 10**9 / abs(vmax - vmin)))), 9) | ||
# print(x, pos, n_decimals) | ||
return self.format_timedelta_ticks(x, pos, n_decimals) |
Oops, something went wrong.