plots ¶
Plot EMG signals in time and frequency.
PSD axes are labelled in mV^2/Hz, which assumes the data is in mV.
plot_ch ¶
plot_ch(data: ndarray, timestamps: ndarray, delta: Optional[int] = 5, ax: Optional[Axes] = None, palette_name: Optional[str] = 'viridis', **kwarg: Optional[Union[str, int, float]]) -> plt.Axes
Plot all channels stacked vertically in a single axes.
Each channel is shifted up by max(data) / delta times its index. Every fifth
channel is labelled on the y axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Float data with shape (samples, chs). |
required |
timestamps
|
ndarray
|
Time of each sample in seconds, with shape (samples,). |
required |
delta
|
int
|
Divisor of the data maximum that sets the spacing between channels. Larger values bring channels closer. Default is 5. |
5
|
ax
|
Axes
|
Axes to plot on. Default is None, which creates a new figure. |
None
|
palette_name
|
str
|
Name of the seaborn palette used to colour the channels. Default is "viridis". |
'viridis'
|
**kwarg
|
Optional[Union[str, int, float]]
|
Additional keyword arguments passed to |
{}
|
Returns:
| Type | Description |
|---|---|
Axes
|
plt.Axes: Axes where the data is plotted. |
Source code in emg_tools/plots.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
plot_ch_map ¶
plot_ch_map(values: ndarray, ch_map: ndarray, bad_ch: Optional[ndarray] = None, ax: Optional[Axes] = None, palette_name: Optional[str] = 'viridis', cbar_label: Optional[str] = None, **kwarg: Optional[Union[str, int, float]]) -> plt.Axes
Plot one value per channel on the electrode grid, annotated with channel numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ndarray
|
Value per channel with shape (channels,). |
required |
ch_map
|
ndarray
|
Channel map with shape (rows, cols). Empty cells (-1) are left blank. |
required |
bad_ch
|
ndarray
|
Channels outlined in red. Default is None. |
None
|
ax
|
Axes
|
Axes to plot the map. Default is None. |
None
|
palette_name
|
str
|
Name of the colormap. Default is "viridis". |
'viridis'
|
cbar_label
|
str
|
Colorbar label. Default is None. |
None
|
**kwarg
|
Optional[Union[str, int, float]]
|
Additional keyword arguments to be passed to the |
{}
|
Returns:
| Type | Description |
|---|---|
Axes
|
plt.Axes: Axes where the map is plotted. |
Source code in emg_tools/plots.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
plot_psd ¶
plot_psd(data: ndarray, fs: Optional[int] = 2048, ax: Optional[Axes] = None, palette_name: Optional[str] = 'viridis', log_scale: Optional[bool] = False, **kwarg: Optional[Union[str, int, float]]) -> plt.Axes
Plot the periodogram PSD of each channel as one line per channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input data with shape (samples, chs). |
required |
fs
|
int
|
Sampling frequency in Hz. Default is 2048. |
2048
|
ax
|
Axes
|
Axes to plot on. Default is None, which creates a new figure. |
None
|
palette_name
|
str
|
Name of the seaborn palette used to colour the channels. Default is "viridis". |
'viridis'
|
log_scale
|
bool
|
If True, the PSD axis is logarithmic. Default is False. |
False
|
**kwarg
|
Optional[Union[str, int, float]]
|
Additional keyword arguments passed to |
{}
|
Returns:
| Type | Description |
|---|---|
Axes
|
plt.Axes: Axes where the PSD is plotted. |
Source code in emg_tools/plots.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
plot_psd_map ¶
plot_psd_map(data: ndarray, fs: Optional[int] = 2048, ax: Optional[Axes] = None, log_scale: Optional[bool] = False, eps: Optional[float] = None, palette_name: Optional[str] = 'viridis', **kwarg: Optional[Union[str, int, float]]) -> plt.Axes
Plot the periodogram PSD as a heatmap of frequency against channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input data with shape (samples, chs). |
required |
fs
|
int
|
Sampling frequency in Hz. Default is 2048. |
2048
|
ax
|
Axes
|
Axes to plot on. Default is None, which creates a new figure. |
None
|
log_scale
|
bool
|
If True, the colour scale is logarithmic. Default is False. |
False
|
eps
|
float
|
Lower limit of the log colour scale, to avoid log(0). Only used if log_scale is True. Default is None, which uses the smallest positive PSD value. |
None
|
palette_name
|
str
|
Name of the matplotlib colormap. Default is "viridis". |
'viridis'
|
**kwarg
|
Optional[Union[str, int, float]]
|
Additional keyword arguments passed to
|
{}
|
Returns:
| Type | Description |
|---|---|
Axes
|
plt.Axes: Axes where the PSD is plotted. |
Source code in emg_tools/plots.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
plot_comp_spectrogram ¶
plot_comp_spectrogram(data: ndarray, fs: Optional[int] = 2048, ax: Optional[Union[Axes, ndarray]] = None, log_scale: Optional[bool] = False, eps: Optional[float] = None, palette_name: Optional[str] = 'viridis', **kwarg: Optional[Union[str, int, float]]) -> np.ndarray
Compute the spectrogram of each channel and plot it with plot_spectrogram.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input data with shape (samples, chs) or (samples,). |
required |
fs
|
int
|
Sampling frequency in Hz. Default is 2048. |
2048
|
ax
|
Axes or ndarray
|
Axes to plot on, one per channel. Default is None, which creates one row of axes per channel. |
None
|
log_scale
|
bool
|
If True, the colour scale is logarithmic. Default is False. |
False
|
eps
|
float
|
Lower limit of the colour scale. Default is None, which uses the smallest positive value in log scale and the minimum otherwise. |
None
|
palette_name
|
str
|
Name of the matplotlib colormap. Default is "viridis". |
'viridis'
|
**kwarg
|
Optional[Union[str, int, float]]
|
Additional keyword arguments passed to
|
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Array of axes where the spectrogram of each channel is plotted. |
Source code in emg_tools/plots.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
plot_spectrogram ¶
plot_spectrogram(f: ndarray, t: ndarray, sxx: ndarray, ax: Optional[Union[Axes, ndarray]] = None, palette_name: Optional[str] = 'magma', log_scale: Optional[bool] = False, eps: Optional[float] = None, **kwarg: Optional[Union[str, int, float]]) -> np.ndarray
Plot a precomputed spectrogram, one axes per signal.
All signals share the same colour scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
ndarray
|
Frequencies in Hz, with shape (freqs,). |
required |
t
|
ndarray
|
Times in seconds, with shape (times,). |
required |
sxx
|
ndarray
|
Spectrogram with shape (freqs, times, signals), or (freqs, times) for a single signal. |
required |
ax
|
Axes or ndarray
|
Axes to plot on, one per signal. Default is None, which creates one row of axes per signal. |
None
|
palette_name
|
str
|
Name of the matplotlib colormap. Default is "magma". |
'magma'
|
log_scale
|
bool
|
If True, the colour scale is logarithmic. Default is False. |
False
|
eps
|
float
|
Lower limit of the colour scale. Default is None, which uses the smallest positive value in log scale and the minimum otherwise. |
None
|
**kwarg
|
Optional[Union[str, int, float]]
|
Additional keyword arguments passed to
|
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Array of axes where the spectrogram of each signal is plotted. |
Source code in emg_tools/plots.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |