Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Correct subplot positioning in plot_forecasts #180

Closed
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
12 changes: 6 additions & 6 deletions functime/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ def plot_forecasts(
if isinstance(y_true, pl.DataFrame):
y_true = y_true.lazy()

# Get most recent observations
# Get the unique entities
entities = y_true.select(pl.col(entity_col).unique(maintain_order=True)).collect()

# Get sampled entities
entities_sample = entities.to_series().sample(n_series, seed=seed)

# Get most recent observations
# Get the most recent observations for the sampled entities
y = (
y_true.filter(pl.col(entity_col).is_in(entities_sample))
.group_by(entity_col)
Expand All @@ -200,11 +200,11 @@ def plot_forecasts(
)

# Organize subplots
n_rows = n_series // n_cols
n_rows = n_series // n_cols + (n_series % n_cols > 0)
row_idx = np.repeat(range(n_rows), n_cols)
fig = make_subplots(rows=n_rows, cols=n_cols, subplot_titles=entities)
fig = make_subplots(rows=n_rows, cols=n_cols, subplot_titles=entities_sample)

for i, entity_id in enumerate(entities):
for i, entity_id in enumerate(entities_sample):
ts = y.filter(pl.col(entity_col) == entity_id)
ts_pred = y_pred.filter(pl.col(entity_col) == entity_id)
row = row_idx[i] + 1
Expand Down