Skip to content

Commit 8ae7f0a

Browse files
committed
Improve plotting method within Raw class
1 parent 1d6537f commit 8ae7f0a

2 files changed

Lines changed: 24998 additions & 152 deletions

File tree

circStudio/io/base.py

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,34 @@ def __init__(
3636
mask=None,
3737
)
3838

39-
def plot(self, mode="activity", log=False):
39+
def plot(self, mode="activity", ts=None, log=False):
40+
"""
41+
Plotting method for actigraphy data.
42+
43+
Parameters
44+
----------
45+
ts : str, optional
46+
In case the user wants to plot a time series (ts) other than light or activity,
47+
name of the vector to be used
48+
mode : str
49+
Either 'activity', 'light' or 'ts'. In case the user wants to plot a time series
50+
other than light or activity.
51+
log : bool
52+
Whether or not to log data (log_{10]+1).
53+
54+
Returns
55+
-------
56+
go.Figure
57+
Plot of activity or light data.
58+
"""
59+
if ts is not None:
60+
mode = None
61+
4062
match mode:
4163
case "activity":
4264
# Define layout for activity plot
4365
layout = go.Layout(
44-
title="Activity time series",
66+
title=f"Activity time series",
4567
xaxis=dict(title="DateTime"),
4668
yaxis=dict(title="Activity"),
4769
showlegend=False,
@@ -67,8 +89,8 @@ def plot(self, mode="activity", log=False):
6789
# Define layout for light plot
6890
layout = go.Layout(
6991
title="Light time series",
70-
xaxis=dict(title="DateTime"),
71-
yaxis=dict(title="Activity"),
92+
xaxis=dict(title="Datetime"),
93+
yaxis=dict(title="Light"),
7294
showlegend=False,
7395
)
7496
if log:
@@ -88,7 +110,31 @@ def plot(self, mode="activity", log=False):
88110
layout=layout,
89111
)
90112
case _:
91-
print('Currently, the plot method only supports "activity" and "light"')
113+
if ts is not None and ts in self.df.columns:
114+
layout = go.Layout(
115+
title=f"{ts.lower().capitalize()} time series",
116+
xaxis=dict(title="Datetime"),
117+
yaxis=dict(title=f"{ts.lower().capitalize()}"),
118+
showlegend=False,
119+
)
120+
if log:
121+
return go.Figure(
122+
data=go.Scatter(
123+
x=self.df[ts].index.astype(str), y=np.log10(self.df[ts] + 1)
124+
),
125+
layout=layout,
126+
)
127+
else:
128+
return go.Figure(
129+
data=go.Scatter(
130+
x=self.df[ts].index.astype(str), y=self.df[ts]
131+
),
132+
layout=layout,
133+
)
134+
else:
135+
print('No column was found with the specified name.')
136+
137+
92138

93139
def length(self):
94140
r"""Number of activity data acquisition points"""

docs/source/tutorial_1.ipynb

Lines changed: 24947 additions & 147 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)