Skip to content

Commit

Permalink
fix alpha specification for segment plots
Browse files Browse the repository at this point in the history
  • Loading branch information
DominiqueMakowski committed Aug 28, 2023
1 parent 045ae92 commit 60884fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions neurokit2/ecg/ecg_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ def _ecg_segment_plot(heartbeats, heartrate=0, ytitle="ECG", color="#F44336", ax
)

# Alpha of individual beats decreases with more heartbeats
alpha = 1 / np.log1p(np.log2(1 + df_pivoted.shape[1]))
alpha = 1 / np.log2(np.log2(1 + df_pivoted.shape[1]))

# Plot all heartbeats
ax.plot(df_pivoted, color="grey", linewidth=alpha, zorder=2)
ax.plot(df_pivoted, color="grey", linewidth=alpha, alpha=alpha, zorder=2)

# Plot individual waves
for wave in [
Expand Down
17 changes: 16 additions & 1 deletion neurokit2/stats/rescale.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ def rescale(data, to=[0, 1], scale=None):
data : Union[list, np.array, pd.Series]
Raw data.
to : list
New range of values of the data after rescaling.
New range of values of the data after rescaling. Must be a list or tuple of two values. If
more values, the function will assume it is another signal and will derive the min and max
from it.
scale : list
A list or tuple of two values specifying the actual range
of the data. If ``None``, the minimum and the maximum of the
Expand All @@ -30,9 +32,22 @@ def rescale(data, to=[0, 1], scale=None):
import neurokit2 as nk
# Normalize to 0-1
nk.rescale([3, 1, 2, 4, 6], to=[0, 1])
# Rescale to 0-1, but specify that 0 corresponds to another value that the
# minimum of the data.
nk.rescale([3, 1, 2, 4, 6], to=[0, 1], scale=[0, 6])
# Rescale to 0-4 (the min-max of another signal)
nk.rescale([3, 1, 2, 4, 6], to=[0, 1, 3, 4])
"""
# Sanity checks
if len(to) < 2:
raise ValueError("'to' must have at least 2 values.")
if len(to) > 2: # We assume it is a signal
to = [np.nanmin(to), np.nanmax(to)]

# Return appropriate type
if isinstance(data, list):
Expand Down

0 comments on commit 60884fb

Please sign in to comment.