Refactor kde_distributions and extract density overlay logic into plot utilities#110
Merged
Conversation
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.
Refactoring the existing
kde_distributionsplotting function to improve clarity, extensibility, and internal structure. Density overlay logic (KDE and parametric PDFs) has been extracted into a dedicated utility function housed in a new_plot_utils.pymodule.Key Changes
Extracted density overlay logic
Moved all KDE and parametric density plotting into
_plot_density_overlays, a reusable internal helper that enforces a single, consistent color pipeline for all density curves.Decoupled orchestration from rendering
kde_distributionsnow focuses on high-level plotting flow (grid layout, labeling, legends, saving), while_plot_density_overlayshandles low-level density rendering.Expanded density support beyond KDE
Density overlays now support any valid
scipy.statsdistribution (e.g.,norm,lognorm,gamma) in addition to KDE, with explicit validation and clear error messaging for invalid inputs.Supported options include:
kde,alpha,anglit,arcsine,argus,beta,betaprime,bradford,burr,burr12,cauchy,chi,chi2,cosine,crystalball,dgamma,dpareto_lognorm,dweibull,erlang,expon,exponnorm,exponpow,exponweib,f,fatiguelife,fisk,foldcauchy,foldnorm,gamma,gausshyper,genexpon,genextreme,gengamma,genhalflogistic,genhyperbolic,geninvgauss,genlogistic,gennorm,genpareto,gibrat,gompertz,gumbel_l,gumbel_r,halfcauchy,halfgennorm,halflogistic,halfnorm,hypsecant,invgamma,invgauss,invweibull,irwinhall,jf_skew_t,johnsonsb,johnsonsu,kappa3,kappa4,ksone,kstwo,kstwobign,landau,laplace,laplace_asymmetric,levy,levy_l,levy_stable,loggamma,logistic,loglaplace,lognorm,loguniform,lomax,maxwell,mielke,moyal,multivariate_normal,nakagami,ncf,nct,ncx2,norm,norminvgauss,pareto,pearson3,powerlaw,powerlognorm,powernorm,rayleigh,rdist,recipinvgauss,reciprocal,rel_breitwigner,rice,rv_continuous,rv_histogram,semicircular,skewcauchy,skewnorm,studentized_range,t,trapezoid,triang,truncexpon,truncnorm,truncpareto,truncweibull_min,tukeylambda,uniform,vonmises,vonmises_fisher,vonmises_line,wald,weibull_max,weibull_min,wrapcauchy.Improved API semantics
density_colorfor clarity and consistency.plot_typeno longer exposes"kde"as a top-level mode; KDE is treated as one possible density function.density_functionvalues raise explicit, readable errors.Internal utilities module introduced
Added
_plot_utils.pyto house reusable plotting helpers, reducing duplication and keepingplots.pyfocused on public-facing API behavior.Backward Compatibility
kde_distributionsinterface is preserved (and may be aliased if renamed in a follow-up PR).Why this matters
This refactor improves maintainability, reduces internal complexity, and makes it easier to extend distribution plotting without bloating the main plotting API.