-
Notifications
You must be signed in to change notification settings - Fork 18
Add ridgeline plot feature #451
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
Open
cvanelteren
wants to merge
8
commits into
main
Choose a base branch
from
feature/ridgeline-plot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+977
−5
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
Implements ridgeline plots (also known as joyplots) for visualizing distributions of multiple datasets as stacked, overlapping density curves. Features: - Support for both vertical (traditional) and horizontal orientations - Kernel density estimation (KDE) for smooth curves - Histogram mode for binned bar charts (hist=True) - Customizable overlap between ridges - Color specification via colormap or custom colors - Integration with UltraPlot's color cycle - Transparent error handling for invalid distributions - Follows UltraPlot's docstring snippet manager pattern Methods added: - ridgeline(): Create vertical ridgeline plots - ridgelineh(): Create horizontal ridgeline plots - _apply_ridgeline(): Internal implementation Tests added: - test_ridgeline_basic: Basic KDE functionality - test_ridgeline_colormap: Colormap support - test_ridgeline_horizontal: Horizontal orientation - test_ridgeline_custom_colors: Custom color specification - test_ridgeline_histogram: Histogram mode - test_ridgeline_histogram_colormap: Histogram with colormap - test_ridgeline_comparison_kde_vs_hist: KDE vs histogram comparison - test_ridgeline_empty_data: Error handling for empty data - test_ridgeline_label_mismatch: Error handling for label mismatch Docstrings registered with snippet manager following UltraPlot conventions.
67d6388 to
bb2308c
Compare
The ridge outlines now only trace the top curve of each distribution, not the baseline. This is achieved by: - Using fill_between/fill_betweenx with edgecolor='none' - Drawing a separate plot() line on top for the outline - Proper z-ordering to ensure outline appears above fill This creates cleaner ridgeline plots where the baseline doesn't have a visible edge line connecting the endpoints.
Implements explicit z-ordering to ensure proper layering: - Each ridge i gets: fill at base+i*2, outline at base+i*2+1 - Later ridges appear on top of earlier ridges - Outline always appears on top of its corresponding fill - Base zorder defaults to 2 (above grid/axes elements) - User can override base zorder via zorder parameter This ensures clean visual layering even with high overlap values and when other plot elements are present (e.g., grids).
Reversed the z-order assignment so that visually lower ridges (smaller index, closer to viewer) have higher z-order values. Z-order formula: fill_zorder = base + (n_ridges - i - 1) * 2 This ensures proper visual layering where: - Ridge 0 (bottom, front) has highest z-order - Ridge n-1 (top, back) has lowest z-order This prevents ridges from incorrectly popping in front of others when overlap is high, maintaining the correct visual depth.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Replaced explicit bandwidth/weights parameters with a more flexible
kde_kw dictionary that passes all kwargs to scipy.stats.gaussian_kde.
Features:
- kde_kw: dict parameter for passing any KDE arguments (bw_method, weights, etc.)
- points: int parameter to control number of evaluation points (default 200)
- More maintainable and extensible than exposing individual parameters
- Follows UltraPlot's convention of using *_kw parameters
Example usage:
- Custom bandwidth: kde_kw={'bw_method': 0.5}
- With weights: kde_kw={'weights': weight_array}
- Silverman method: kde_kw={'bw_method': 'silverman'}
- Smoother curves: points=500
Tests added:
- test_ridgeline_kde_kw: Tests various kde_kw configurations
- test_ridgeline_points: Tests points parameter
Collaborator
Author
|
need to check a few more plots to see if this is what I invisioned. |
…plots Implements two distinct positioning modes for ridgeline plots: 1. Categorical Positioning (default): Evenly-spaced ridges with discrete labels - Uses overlap parameter to control spacing - Traditional 'joyplot' aesthetic 2. Continuous Positioning: Ridges anchored to specific Y-coordinates - Enabled by providing 'positions' parameter - 'height' parameter controls ridge height in Y-axis units - Essential for scientific plots where Y-axis represents physical variables - Supports: time series, depth profiles, redshift distributions, etc. Parameters: - positions: Array of Y-coordinates for each ridge - height: Ridge height in Y-axis units (auto-determined if not provided) Scientific use cases: - Ocean temperature profiles vs depth - Galaxy distributions vs redshift - Climate data over time - Atmospheric profiles vs altitude - Any data where the vertical axis has physical meaning Tests added: - test_ridgeline_continuous_positioning: Visual test of continuous mode - test_ridgeline_continuous_vs_categorical: Side-by-side comparison - test_ridgeline_continuous_errors: Error handling validation - test_ridgeline_continuous_auto_height: Auto height calculation
- Add comprehensive ridgeline plot examples to docs/stats.py - Include examples for KDE vs histogram modes - Demonstrate categorical vs continuous positioning for scientific use cases - Replace deprecated mcm.get_cmap() with constructor.Colormap() - All 15 ridgeline tests still passing
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.
Closes #450
Implements ridgeline plots (also known as joyplots) for visualizing distributions of multiple datasets as stacked, overlapping density curves.
Features:
Methods added:
Tests added: