Add optional matplotlib plotting API faithful to R NNS - #12
Merged
Conversation
Introduce `nns.plotting`, an optional (`ovvo-nns[plot]`) visual plotting subpackage that is color/element-faithful to R NNS `plot = TRUE` output but not pixel-diffed. - pyproject: add `[plot]` optional extra (matplotlib>=3.7); keep core NumPy/SciPy-only; matplotlib imported lazily per function with a clear ImportError when absent. Add mypy override for matplotlib.*. - palette.py: pin exact R grDevices hex, flagging the fidelity traps where R and matplotlib disagree (green -> #00FF00, grey -> #BEBEBE); rainbow() emulates R's HSV rainbow(n). - Plot functions for reg, part, arma, arma_optim, cdf/VaR, fsd/ssd/tsd, anova, causation, norm, seas, diff, and copula. Each takes a computed result (or the same inputs) plus ax=None, returns the Axes, and never calls plt.show(). - tests/plotting: Agg-backend tests asserting artist colors and which element they sit on (no pixel/PDF comparison); palette trap tests; lazy-import tests. - docs/plot_parity_policy.md + README: document the new opt-in API. - CI: install the plot extra and run the plotting color-fidelity tests.
Plotting now ships in the single package: matplotlib moves from the `[plot]` optional extra into core `dependencies`, and the extra is removed. - pyproject: matplotlib>=3.7 in [project.dependencies]; drop [project.optional-dependencies] and the now-unneeded mypy matplotlib override and dev duplicate. - _mpl.py / __init__/docs/README: matplotlib is still imported lazily (so `import nns` stays light) but is no longer described as optional; error hint and lazy-import test updated accordingly. - CI: install plain `-e .` (matplotlib comes via core deps).
Fold in the release-readiness gate from PR #11 so it can be merged alongside the plotting work: a new `check_metadata` job runs `twine check --strict` over the built wheels + sdist with pinned `twine>=6.1` / `packaging>=24.2`, and both `publish_testpypi` and `publish_pypi` now depend on it. This fails a metadata or README-rendering problem before anything is published. The matplotlib core-dependency change from PR #11 is already present on this branch, so only the workflow gate is ported here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds an optional
nns.plottingsubpackage that provides matplotlib-based visualization functions faithful to the R NNS package'splot = TRUEoutput. The plotting API is entirely optional—matplotlib is not a core dependency and is imported lazily only when plotting functions are called.Key Changes
New
nns.plottingsubpackage with 11 plot functions covering regression, ARMA forecasting, stochastic dominance, ANOVA, causation, CDF/VaR, seasonality, normalization, differentiation, and copula analysisplot_nns_reg,plot_nns_part— regression and partition mappingplot_nns_arma,plot_nns_arma_optim— ARMA forecasts with prediction intervalsplot_fsd,plot_ssd,plot_tsd— first/second/third-order stochastic dominanceplot_nns_anova— ANOVA group boxplotsplot_nns_causation— standardized series comparisonplot_nns_cdf— empirical CDF with VaR overlaysplot_nns_seas— seasonality test resultsplot_nns_norm— normalization line/boxplot chartsplot_nns_diff— numerical differentiation geometryplot_nns_copula— 2-D/3-D copula scatter with orthant coloringColor/element fidelity to R via
nns.plotting.palette:grDevicescolors, especially the fidelity traps where R and matplotlib disagree (e.g., Rgreenis#00FF00, matplotlibgreenis#008000)rainbow(n)HSV sweep for multi-series plotsLazy matplotlib loading in
nns.plotting._mpl:require_mpl()on demandImportErrorif matplotlib is absent:"install ovvo-nns[plot]"Comprehensive test suite (
tests/plotting/):Updated documentation and configuration:
docs/plot_parity_policy.mdclarified: graphics are color/element-faithful but not pixel-comparedpyproject.tomladds optional[project.optional-dependencies].plot = ["matplotlib>=3.7"]README.mddocuments the optional plotting extraImplementation Details
ax=None, return the matplotlibAxes(orFigurefor 3-D), never callplt.show()col=usage intools/NNS/R/*.Rsource fileshttps://claude.ai/code/session_01B2z9DRMNCydHrpRQUA6HBW