Skip to content

feat: add plot_ts for time series visualization (closes #322)#439

Open
jinukuntlaakhilakumargoud-web wants to merge 1 commit intoarviz-devs:mainfrom
jinukuntlaakhilakumargoud-web:feat/plot-ts-issue-322
Open

feat: add plot_ts for time series visualization (closes #322)#439
jinukuntlaakhilakumargoud-web wants to merge 1 commit intoarviz-devs:mainfrom
jinukuntlaakhilakumargoud-web:feat/plot-ts-issue-322

Conversation

@jinukuntlaakhilakumargoud-web
Copy link
Copy Markdown

Summary

Implements plot_ts - a new time series plot (issue #322). This adds parity with the legacy arviz.plot_ts function using the new modular PlotCollection-based architecture, following the pattern established by plot_lm.

New file: src/arviz_plots/plots/ts_plot.py

Visual elements

Key Visual fn Description
observed_line line_xy Observed data line (pre-holdout)
posterior_predictive line_xy N posterior predictive sample lines
observed_scatter scatter_xy Holdout observed data points
forecast line_xy N forecast sample lines (post-split)
vline vline Vertical divider at train/holdout boundary
xlabel / ylabel labelled_x/y Axis labels

Key parameters

  • y, x - pre-holdout observed variable and time axis
    • y_hat - posterior predictive variable for in-sample trajectories
    • y_holdout, y_forecasts - holdout observed and forecast variables
    • num_samples - number of PP sample lines to draw (default 50)
    • sample_dims, coords, filter_vars, visuals, aes_by_visuals, **pc_kwargs - standard ArviZ-plots pattern

Implementation notes

  • Follows the ppc_dist_plot pattern for PP samples: stacks sample_dims into a flat sample dimension and uses overlay_ppc aesthetic
    • Uses a _combine_xy helper (similar to combine_sort_smooth in plot_lm) to build plot_axis-shaped datasets for line_xy / scatter_xy
    • Correctly renames holdout/forecast variables to match y variable names for PlotCollection.map() alignment

Tests: tests/test_ts_plot.py

7 tests covering:

  • Basic observed line only
    • Posterior predictive sample lines (y_hat)
    • Holdout scatter + vline (y_holdout)
    • Forecast lines (y_forecasts)
    • Full combination (all visuals)
    • Visual disabling (visuals={"observed_line": False})
    • Error handling (invalid plot_dim)
pytest tests/test_ts_plot.py -k none
# 7 passed

@read-the-docs-community
Copy link
Copy Markdown

Documentation build overview

📚 arviz-plots | 🛠️ Build #31586926 | 📁 Comparing 63cf15a against latest (294b5c5)


🔍 Preview build

Show files changed (57 files in total): 📝 57 modified | ➕ 0 added | ➖ 0 deleted
File Status
gallery/add_reference_bands.html 📝 modified
gallery/add_reference_lines.html 📝 modified
gallery/combine_plots.html 📝 modified
gallery/plot_autocorr.html 📝 modified
gallery/plot_bf.html 📝 modified
gallery/plot_compare.html 📝 modified
gallery/plot_convergence_dist.html 📝 modified
gallery/plot_dgof.html 📝 modified
gallery/plot_dgof_dist.html 📝 modified
gallery/plot_dist_ecdf.html 📝 modified
gallery/plot_dist_hist.html 📝 modified
gallery/plot_dist_kde.html 📝 modified
gallery/plot_dist_models.html 📝 modified
gallery/plot_dist_qds.html 📝 modified
gallery/plot_ecdf_coverage.html 📝 modified
gallery/plot_ecdf_pit.html 📝 modified
gallery/plot_energy.html 📝 modified
gallery/plot_ess_evolution.html 📝 modified
gallery/plot_ess_local.html 📝 modified
gallery/plot_ess_models.html 📝 modified
gallery/plot_ess_quantile.html 📝 modified
gallery/plot_forest.html 📝 modified
gallery/plot_forest_ess.html 📝 modified
gallery/plot_forest_models.html 📝 modified
gallery/plot_forest_pp_obs.html 📝 modified
gallery/plot_forest_shade.html 📝 modified
gallery/plot_khat.html 📝 modified
gallery/plot_khat_aesthetics.html 📝 modified
gallery/plot_khat_facet_cols.html 📝 modified
gallery/plot_khat_facet_grid.html 📝 modified
gallery/plot_lm.html 📝 modified
gallery/plot_loo_pit.html 📝 modified
gallery/plot_mcse.html 📝 modified
gallery/plot_pair.html 📝 modified
gallery/plot_pair_distribution.html 📝 modified
gallery/plot_pair_focus.html 📝 modified
gallery/plot_pair_focus_distribution.html 📝 modified
gallery/plot_parallel.html 📝 modified
gallery/plot_pava_calibration.html 📝 modified
gallery/plot_ppc_censored.html 📝 modified
gallery/plot_ppc_coverage.html 📝 modified
gallery/plot_ppc_dist.html 📝 modified
gallery/plot_ppc_interval.html 📝 modified
gallery/plot_ppc_pava_residuals.html 📝 modified
gallery/plot_ppc_pit.html 📝 modified
gallery/plot_ppc_rootogram.html 📝 modified
gallery/plot_ppc_tstat.html 📝 modified
gallery/plot_prior_posterior.html 📝 modified
gallery/plot_psense.html 📝 modified
gallery/plot_psense_quantities.html 📝 modified
gallery/plot_rank.html 📝 modified
gallery/plot_rank_dist.html 📝 modified
gallery/plot_ridge.html 📝 modified
gallery/plot_ridge_multiple.html 📝 modified
gallery/plot_trace.html 📝 modified
gallery/plot_trace_dist.html 📝 modified
api/generated/arviz_plots.PlotCollection.generate_aes_dt.html 📝 modified

@aloctavodia
Copy link
Copy Markdown
Contributor

@jinukuntlaakhilakumargoud-web, usually, if you see that another person says they are working on an issue, you should not work on that issue.

@aloctavodia
Copy link
Copy Markdown
Contributor

@rohanbabbar04 can you check this?

@jinukuntlaakhilakumargoud-web
Copy link
Copy Markdown
Author

@aloctavodia Ah, I sincerely apologize! I am still getting used to the open-source workflow and completely missed that @rohanbabbar04 had already claimed issue #322 before I started. That is entirely my fault.

@rohanbabbar04 I didn't mean to step on your toes. Since I already pushed this up, please feel completely free to use my branch as a starting point, review this PR, or if you prefer to build it from scratch yourself, just let me know and I will close this PR! Whatever works best for you.

@OriolAbril
Copy link
Copy Markdown
Member

@jinukuntlaakhilakumargoud-web for future reference: https://python.arviz.org/en/latest/contributing/contributing_prs.html#steps-before-starting-work (most relevant piece quoted below)

If an issue ticket exists

If an issue exists, check the ticket to ensure no one else has started working on it. If you are first to start work, comment on the ticket to make it evident to others. If the comment looks old or abandoned, leave a comment asking if you may start work.

@rohanbabbar04
Copy link
Copy Markdown
Contributor

@rohanbabbar04 can you check this?

Yeah, I can check this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants