Visualization¶
Functions for visualizing time series data and components using lets_plot.
plot_components¶
plot_components(dataset: Dict, sample_indices: Union[int, List[int], Dict[int, int], None] = None, components: List[str] = None, dimensions: List[int] = None, show_indicators: bool = True, line_color: str = 'black', line_size: float = 1.5, hline_intercept: float = 0, rect_fill: str = 'red', rect_alpha: float = 0.25, facet_order: Dict[str, str] = {'y': 'class', 'x': 'component'}, x_order: int = 1, y_order: int = 1, panel_width: int = 250, panel_height: int = 150) -> Union[Any, List[Any]]
¶
Create time series visualization with feature indicators as rectangles.
This function visualizes time series data by showing its components (aggregated series, background, features) with options to highlight feature locations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Dict
|
Dataset containing time series data and components. |
required |
sample_indices
|
Union[int, List[int], Dict[int, int], None]
|
Specifies which samples to visualize. Note: This function shows ONE sample per class for comparison purposes. Can be provided in several formats: - int: A single sample index (shows that sample and its class) - List[int]: Multiple sample indices. These are grouped by class, and if multiple samples belong to the same class, only the last one is shown. - Dict[int, int]: Mapping from class labels to sample indices (e.g., {0: 5, 1: 10} means sample at index 5 for class 0, sample at index 10 for class 1). The sample at each index must actually belong to the specified class. - None: Use first sample from each class (default behavior) |
None
|
components
|
Optional[List[str]]
|
List of components to include. Can be used to exclude certain components. Default: ["aggregated", "features", "background"]. |
None
|
dimensions
|
Optional[List[int]]
|
List of dimensions to include. If None, include all dimensions. For multivariate time series, this allows selecting specific dimensions. |
None
|
show_indicators
|
bool
|
Whether to show feature indicators. |
True
|
line_color
|
str
|
Color of the time series lines. |
'black'
|
line_size
|
float
|
Size of the time series lines. |
1.5
|
hline_intercept
|
float
|
Y-intercept for horizontal line at y=hline_intercept. If None, no line is shown. |
0
|
rect_fill
|
str
|
Fill color for feature rectangles. |
'red'
|
rect_alpha
|
float
|
Alpha transparency for feature rectangles. |
0.25
|
facet_order
|
Dict[str, str]
|
Order of facets, dict with "x" and "y" keys. x corresponds to columns, y to rows. |
{'y': 'class', 'x': 'component'}
|
x_order
|
int
|
Order of x-axis facets. 1=ascending, -1=descending, 0=no order. Uses names of the column facet variable. |
1
|
y_order
|
int
|
Order of y-axis facets. 1=ascending, -1=descending, 0=no order. Uses names of the row facet variable. |
1
|
panel_width
|
int
|
Width of each panel in pixels. |
250
|
panel_height
|
int
|
Height of each panel in pixels. |
150
|
Returns:
| Type | Description |
|---|---|
Union[Any, List[Any]]
|
Union[Any, List[Any]]: lets_plot visualization or list of visualizations for multivariate data. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If a sample index is out of range. |
Examples:
Show first sample of each class (default)¶
plot_components(dataset)
Show a specific sample by index (shows only the class of that sample)¶
plot_components(dataset, sample_indices=5)
Show samples from different classes (grouped by class, one sample per class)¶
If indices 0, 10, 20 are from classes 0, 1, 0 respectively, only samples 10 and 20¶
will be shown (last sample for class 0, and sample 10 for class 1)¶
plot_components(dataset, sample_indices=[0, 10, 20])
Explicit mapping: show sample 5 for class 0, sample 10 for class 1¶
(the sample at index 5 must belong to class 0, and sample at index 10 to class 1)¶
plot_components(dataset, sample_indices={0: 5, 1: 10})
Source code in xaitimesynth/visualization.py
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 | |
plot_component¶
plot_component(signal: np.ndarray = None, component_type: str = None, n_timesteps: int = 100, rng: np.random.RandomState = None, width: int = 500, height: int = 250, line_color: str = 'black', line_size: float = 1.5, hline_intercept: float = None, normalization: str = 'none', normalization_kwargs: Dict[str, Any] = None, title: str = None, **kwargs: Any) -> Any
¶
Plot a time series signal generated by one of the generator functions.
This function can be used in two ways: 1. Pass a pre-generated signal array directly 2. Specify a component_type and parameters to generate a new signal
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal
|
Optional[ndarray]
|
Pre-generated signal array. |
None
|
component_type
|
Optional[str]
|
Type of component to generate (if signal not provided). |
None
|
n_timesteps
|
int
|
Length of time series to generate (if signal not provided). |
100
|
rng
|
Optional[RandomState]
|
Random number generator. |
None
|
width
|
int
|
Plot width in pixels. |
500
|
height
|
int
|
Plot height in pixels. |
250
|
line_color
|
str
|
Color of the signal line. |
'black'
|
line_size
|
float
|
Size of the signal line. |
1.5
|
hline_intercept
|
Optional[float]
|
Y-intercept for horizontal line. If None, no line is shown. |
None
|
normalization
|
str
|
Normalization method. Options: "none", "minmax", "zscore". "none" means no normalization, "minmax" scales to [0, 1], "zscore" standardizes. |
'none'
|
normalization_kwargs
|
Optional[Dict[str, Any]]
|
Additional parameters for normalization methods. For "minmax", you can pass feature_range (tuple of min and max). |
None
|
title
|
Optional[str]
|
Title for the plot. |
None
|
**kwargs
|
Any
|
Additional parameters for the generator function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
lets_plot visualization object. |
Source code in xaitimesynth/visualization.py
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 | |
plot_sample¶
plot_sample(X: np.ndarray, y: np.ndarray = None, feature_masks: Dict[str, np.ndarray] = None, components: List[Any] = None, sample_idx: int = 0, components_to_include: List[str] = None, line_color: str = 'black', rect_fill: str = 'red', panel_width: int = 225, panel_height: int = 175) -> Any
¶
Plot a time series sample with its components and feature masks using lets_plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Time series data. |
required |
y
|
Optional[ndarray]
|
Class labels. |
None
|
feature_masks
|
Optional[Dict[str, ndarray]]
|
Dictionary of feature masks. |
None
|
components
|
Optional[List[Any]]
|
List of TimeSeriesComponents objects. |
None
|
sample_idx
|
int
|
Index of the sample to plot. |
0
|
components_to_include
|
Optional[List[str]]
|
List of components to include. |
None
|
line_color
|
str
|
Color of the time series lines. |
'black'
|
rect_fill
|
str
|
Fill color for feature rectangles. |
'red'
|
panel_width
|
int
|
Width of each panel in pixels. |
225
|
panel_height
|
int
|
Height of each panel in pixels. |
175
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
lets_plot visualization. |