Commit f40ecda
authored
feat: add figure combination utilities (overlay, add_secondary_y, update_traces) (#16)
* Files created/modified:
┌───────────────────────────────┬───────────────────────────────────────────────────────────────────────────────┐
│ File │ Changes │
├───────────────────────────────┼───────────────────────────────────────────────────────────────────────────────┤
│ xarray_plotly/figures.py │ Renamed combine_figures → overlay_figures (with alias), added add_secondary_y │
├───────────────────────────────┼───────────────────────────────────────────────────────────────────────────────┤
│ xarray_plotly/__init__.py │ Exported overlay_figures, add_secondary_y, combine_figures │
├───────────────────────────────┼───────────────────────────────────────────────────────────────────────────────┤
│ tests/test_figures.py │ Added 16 new tests for add_secondary_y and alias verification (34 total) │
├───────────────────────────────┼───────────────────────────────────────────────────────────────────────────────┤
│ docs/examples/combining.ipynb │ New notebook demonstrating both methods │
└───────────────────────────────┴───────────────────────────────────────────────────────────────────────────────┘
API:
from xarray_plotly import overlay_figures, add_secondary_y
# Overlay traces on same axes
combined = overlay_figures(area_fig, line_fig)
# Dual y-axis (different scales)
combined = add_secondary_y(temp_fig, precip_fig, secondary_y_title="Rain (mm)")
Features:
- overlay_figures: Supports facets, animation, multiple overlays
- add_secondary_y: Supports animation, custom y-axis title
- Both create deep copies (originals not modified)
- Both validate compatibility and raise clear errors
Test results: 99 tests passing
* Update notebook
* Update notebook
* 1. Added facet support to add_secondary_y - The function now creates secondary y-axes for each facet subplot (e.g., y→y4, y2→y5, y3→y6)
2. Updated tests - Added 6 new tests for faceted secondary y-axis:
- test_matching_facets_works
- test_facets_creates_multiple_secondary_axes
- test_secondary_traces_remapped_to_correct_axes
- test_mismatched_facets_raises
- test_mismatched_facets_reversed_raises
- test_facets_with_custom_title
3. Updated notebook (docs/examples/combining.ipynb):
- Added new "With Facets" section showing add_secondary_y working with faceted figures
- Changed "No Facet Support" limitation to "Mismatched Facet Structure" showing the error when structures don't match
- Updated summary table: add_secondary_y now shows "Yes (must match)" for Facets
4. All 103 tests pass
* Add notebook showing off manipulation options
* Updated the notebook to:
1. Use overlay_figures for adding traces - shown under "Easy: Adding traces to faceted/animated figures"
2. Keep just two helpers:
- update_animation_traces() - the main pain point
- set_animation_speed() - for the deeply nested API
3. Added facets + animation example showing the helper works for both
So the final picture is:
┌─────────────────────────────────────────────────────┬──────────────────────────────────────────┐
│ What you want to do │ Solution │
├─────────────────────────────────────────────────────┼──────────────────────────────────────────┤
│ Add traces to animated/faceted figures │ overlay_figures() ✅ already in library │
├─────────────────────────────────────────────────────┼──────────────────────────────────────────┤
│ Update trace style (line_width, etc.) on animations │ update_animation_traces() - needs helper │
├─────────────────────────────────────────────────────┼──────────────────────────────────────────┤
│ Change animation speed │ set_animation_speed() - needs helper │
├─────────────────────────────────────────────────────┼──────────────────────────────────────────┤
│ Everything else │ Works out of the box │
└─────────────────────────────────────────────────────┴──────────────────────────────────────────┘
Should we add update_animation_traces() and set_animation_speed() to xarray_plotly.figures as proper exported functions? They're simple but solve real pain points.
* Final Public API
from xarray_plotly import (
xpx, # Main entry point - accessor with IDE completion
overlay, # Combine figures on same axes
add_secondary_y, # Dual y-axis plots
update_animation_traces, # Update traces in animation frames
config, # Configuration settings
)
Changes Summary
┌─────────────────────────┬──────────────────────────────────┐
│ Removed │ Reason │
├─────────────────────────┼──────────────────────────────────┤
│ overlay_figures │ Renamed to overlay │
├─────────────────────────┼──────────────────────────────────┤
│ combine_figures │ Alias removed │
├─────────────────────────┼──────────────────────────────────┤
│ SLOT_ORDERS │ Implementation detail │
├─────────────────────────┼──────────────────────────────────┤
│ DataArrayPlotlyAccessor │ Users use xpx() │
├─────────────────────────┼──────────────────────────────────┤
│ DatasetPlotlyAccessor │ Users use xpx() │
├─────────────────────────┼──────────────────────────────────┤
│ auto │ Rarely needed │
├─────────────────────────┼──────────────────────────────────┤
│ set_animation_speed │ Kept as local helper in notebook │
└─────────────────────────┴──────────────────────────────────┘
┌─────────────────────────┬─────────────────────────┐
│ Added │ Reason │
├─────────────────────────┼─────────────────────────┤
│ update_animation_traces │ Was hidden, now exposed │
└─────────────────────────┴─────────────────────────┘
* Rename update_animation_traces to update_traces
* Make module callable
* Revert1 parent f6b4e61 commit f40ecda
File tree
5 files changed
+2384
-2
lines changed- docs/examples
- tests
- xarray_plotly
5 files changed
+2384
-2
lines changed
0 commit comments