plot_spectrum¶
yohou.plotting.signal.plot_spectrum(df, *, columns=None, log_scale=False, groups=None, facet_by='member', facet_n_cols=2, color_palette=None, show_legend=True, title=None, x_label=None, y_label=None, width=None, height=None, connect_gaps=False, line_width=2.0, show_peaks=False, n_peaks=3)
¶
Plot periodogram (power spectral density) for frequency domain analysis.
Creates a periodogram showing the power spectral density via FFT, useful for identifying dominant frequencies and periodic patterns in the data. Hover text always includes the corresponding period (1/frequency) and detected peaks are annotated with their period in sample units.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame with 'time' column and numeric columns. |
required |
columns
|
str | list[str] | None
|
Column(s) to analyze. If None, uses all numeric columns except 'time'. |
None
|
log_scale
|
bool
|
Use logarithmic scale for PSD axis. |
False
|
groups
|
list[str] | None
|
Panel group prefixes to plot. |
None
|
facet_by
|
Literal['group', 'member'] | None
|
Faceting axis for panel data. |
"member"
|
facet_n_cols
|
int
|
Number of columns in facet grid. |
2
|
color_palette
|
list[str] | None
|
Custom color palette. |
None
|
show_legend
|
bool
|
Whether to show the legend. |
True
|
title
|
str | None
|
Plot title. |
None
|
x_label
|
str | None
|
X-axis label. Defaults to "Frequency (cycles/sample)". |
None
|
y_label
|
str | None
|
Y-axis label. Defaults to "Power Spectral Density". |
None
|
width
|
int | None
|
Plot width in pixels. |
None
|
height
|
int | None
|
Plot height in pixels. |
None
|
connect_gaps
|
bool
|
Whether to connect gaps in the data with lines. |
False
|
line_width
|
float
|
Width of the line traces. |
2.0
|
show_peaks
|
bool
|
Whether to annotate dominant frequency peaks. |
False
|
n_peaks
|
int
|
Number of peaks to annotate when |
3
|
Returns¶
| Type | Description |
|---|---|
Figure
|
Plotly figure object. |
Examples¶
>>> # Create sample time series with periodic component
>>> t = np.arange(100)
>>> y = np.sin(2 * np.pi * 0.1 * t) + 0.5 * np.sin(2 * np.pi * 0.25 * t)
>>> df = pl.DataFrame({
... "time": pl.date_range(pl.date(2020, 1, 1), pl.date(2020, 4, 9), "1d", eager=True),
... "y": y,
... })
See Also¶
plot_phase : Plot phase spectrum.
Source Code¶
Show/Hide source
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 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 286 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 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
Tutorials¶
The following example notebooks use this component:
-
How to Visualize Signal Processing
Visualization
Butterworth low-pass filtering with frequency spectrum analysis and phase shift inspection on half-hourly electricity demand data using Plotly.