plot_rolling_statistics¶
yohou.plotting.exploration.plot_rolling_statistics(df, *, columns=None, window_size=7, statistics='mean', show_original=True, 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, resampler=None, line_width=2.0, line_opacity=0.3, smooth_width=2.5, smooth_opacity=0.8)
¶
Plot rolling window statistics (mean, std, min, max, median, quantiles).
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame with 'time' column and numeric columns to plot. |
required |
columns
|
str | list[str] | None
|
Column(s) to compute statistics for. If None, uses all numeric columns except 'time'. |
None
|
window_size
|
int | dict[str, int]
|
Size of the rolling window. When a dict is provided, keys are column names and values are per-column window sizes. |
7
|
statistics
|
str | list[str]
|
Statistic(s) to compute. Options: "mean", "std", "min", "max", "median", "q25" (25th percentile), "q75" (75th percentile), "sum". |
"mean"
|
show_original
|
bool
|
Whether to show the original series alongside the statistics. |
True
|
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. If None, uses yohou palette. |
None
|
show_legend
|
bool
|
Whether to show the legend. |
True
|
title
|
str | None
|
Plot title. |
None
|
x_label
|
str | None
|
X-axis label. |
None
|
y_label
|
str | None
|
Y-axis label. |
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
|
resampler
|
bool | Literal['widget'] | None
|
Enable plotly-resampler for large datasets. |
None
|
line_width
|
float
|
Width of the original series line in pixels. |
2.0
|
line_opacity
|
float
|
Opacity of the original series line. |
0.3
|
smooth_width
|
float
|
Width of the rolling statistic lines in pixels. |
2.5
|
smooth_opacity
|
float
|
Opacity of the rolling statistic lines. |
0.8
|
Returns¶
| Type | Description |
|---|---|
Figure
|
Plotly figure object. |
Examples¶
>>> # Create sample data
>>> df = pl.DataFrame({
... "time": pl.date_range(pl.date(2020, 1, 1), pl.date(2020, 12, 31), "1mo", eager=True),
... "y": [100, 120, 115, 130, 140, 135, 150, 160, 155, 170, 180, 175],
... })
>>> # Simple rolling mean
>>> fig = plot_rolling_statistics(df, window_size=3, statistics="mean")
>>> len(fig.data)
2
>>> # Rolling mean without original
>>> fig = plot_rolling_statistics(df, window_size=3, statistics="mean", show_original=False)
>>> len(fig.data)
1
See Also¶
plot_time_series : Plot basic time series.
Source Code¶
Show/Hide source
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 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 | |
Tutorials¶
The following example notebooks use this component:
-
How to Apply Window Transformations
Data-Features
Feature engineering with LagTransformer, RollingStatisticsTransformer, SlidingWindowFunctionTransformer, and ExponentialMovingAverage on time series data.
-
Exploratory Visualization
Visualization
Exploratory time series visualisation with raw series plots, rolling statistics overlays, seasonal overlays, subseries diagnostics, distribution boxplots, missing data pattern auditing, outlier detection, and resampling comparison.