Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions functime/_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def add_time_series(
self: Self,
*,
data: pl.LazyFrame,
num_points: Optional[int] = None,
num_points: Optional[int | float] = None,
name_on_hover: Optional[str] = None,
legend_group: Optional[str] = None,
**kwargs,
Expand All @@ -185,8 +185,9 @@ def add_time_series(
data : pl.LazyFrame
Panel LazyFrame time series data.
num_points : Optional[int]
Number of data points to plot. If `None`, plot all points.
Defaults to `None`
Number of data points to plot. If `None`, plot all points. If a
float value is passed, plot the corresponding percentage of points.
Defaults to `None`.
name_on_hover : Optional[str]
Text that will be displayed on hover. Defaults to the name of the target column.
legend_group : Optional[str]
Expand Down Expand Up @@ -217,12 +218,20 @@ def add_time_series(
else:
y = data.filter(pl.col(entity_col).is_in(self.entities))

if num_points is not None:
y = y.group_by(entity_col).tail(num_points)
y = y.collect()
if isinstance(num_points, float):
num_points = num_points * y.select(pl.len()).item()
num_points = (
int(num_points)
if num_points == int(num_points)
else int(num_points) + 1
)

y = y.group_by(entity_col).tail(num_points)

self.figure = add_traces(
figure=self.figure,
y=y.collect(),
y=y,
name_on_hover=name_on_hover,
legend_group=legend_group,
num_cols=self.num_cols,
Expand Down
10 changes: 6 additions & 4 deletions functime/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def plot_panel(
*,
num_series: Optional[int] = None,
num_cols: Optional[int] = None,
num_points: Optional[int] = None,
num_points: Optional[int | float] = None,
seed: Optional[int] = None,
layout_kwargs: Optional[Dict[str, Any]] = None,
line_kwargs: Optional[Dict[str, Any]] = None,
Expand All @@ -82,8 +82,9 @@ def plot_panel(
num_series : Optional[int]
Number of entities / time-series to plot. If `None`, plot all entities.
Defaults to `None`.
num_points : Optional[int]
num_points : Optional[int | float]
Plot `last_n` most recent values in `y`. If `None`, plot all points.
If a float value is passed, plot the correspinding percentage of the points.
Defaults to `None`.
num_cols : Optional[int]
Number of columns to arrange subplots. Defaults to 2.
Expand Down Expand Up @@ -127,7 +128,7 @@ def plot_forecasts(
y_pred: Union[pl.DataFrame, pl.LazyFrame],
num_series: Optional[int] = None,
num_cols: Optional[int] = None,
num_points: Optional[int] = None,
num_points: Optional[int | float] = None,
seed: Optional[int] = None,
layout_kwargs: Optional[Dict[str, Any]] = None,
line_kwargs: Optional[Dict[str, Any]] = None,
Expand All @@ -144,6 +145,7 @@ def plot_forecasts(
Defaults to `None`.
num_points : Optional[int]
Plot `last_n` most recent values in `y`. If `None`, plot all points.
If a float value is passed, plot the correspinding percentage of the points.
Defaults to `None`.
num_cols : Optional[int]
Number of columns to arrange subplots. Defaults to 2.
Expand Down Expand Up @@ -200,7 +202,7 @@ def plot_backtests(
*,
num_series: Optional[int] = None,
num_cols: Optional[int] = None,
num_points: Optional[int] = None,
num_points: Optional[int | float] = None,
seed: Optional[int] = None,
layout_kwargs: Optional[Dict[str, Any]] = None,
line_kwargs: Optional[Dict[str, Any]] = None,
Expand Down