Skip to content

Add ax parameter to yasa.topoplot#244

Merged
raphaelvallat merged 1 commit into
masterfrom
topoplot_ax
Mar 29, 2026
Merged

Add ax parameter to yasa.topoplot#244
raphaelvallat merged 1 commit into
masterfrom
topoplot_ax

Conversation

@raphaelvallat
Copy link
Copy Markdown
Owner

Closes #237

Summary

  • Added an ax keyword argument to yasa.topoplot() so the plot can be drawn on a caller-supplied matplotlib.axes.Axes (e.g. a subplot cell).
  • When ax=None (default), behaviour is identical to before — a new figure is created using figsize and dpi.
  • When an ax is provided, the figure is retrieved via ax.get_figure() and the colorbar is placed with fig.colorbar(..., ax=ax) so it adapts to the subplot layout automatically.

Usage

import yasa
import pandas as pd
import matplotlib.pyplot as plt

data1 = pd.Series([4, 8, 7, 1, 2, 3, 5], index=["F4", "F3", "C4", "C3", "P3", "P4", "Oz"], name="NREM")
data2 = pd.Series([2, 5, 4, 3, 6, 7, 4], index=["F4", "F3", "C4", "C3", "P3", "P4", "Oz"], name="REM")

fig, axes = plt.subplots(1, 2, figsize=(8, 4))
yasa.topoplot(data1, ax=axes[0])
yasa.topoplot(data2, ax=axes[1])

Changes

File Change
src/yasa/plotting.py Added ax=None parameter, subplot-aware colorbar logic, and a new docstring example

Comment thread evaluation_review.md
|---|-------|--------|-------|
| 6 | **Log transformation** missing | ⚠️ Deferred | Planned: `log_transform` param + Euser et al. (2008) back-transform. Separate PR. |
| 7 | **Individual discrepancy heatmap** (`indDiscr.R`) | ❌ | No equivalent; data available via `get_sleep_stats()` |
| 8 | **Bug in standalone `groupDiscr.R:117`** (reference code, not YASA) | — | `logTransf=FALSE` should be `TRUE`. Bug in the R file, not YASA |
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bug has been fixed in the latest version of the Menghini pipeline — I was using an outdated version

@raphaelvallat raphaelvallat self-assigned this Mar 29, 2026
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.44444% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.41%. Comparing base (2319677) to head (92697a5).

Files with missing lines Patch % Lines
src/yasa/plotting.py 44.44% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #244      +/-   ##
==========================================
- Coverage   92.57%   92.41%   -0.17%     
==========================================
  Files          13       13              
  Lines        2814     2820       +6     
  Branches      383      385       +2     
==========================================
+ Hits         2605     2606       +1     
- Misses        153      156       +3     
- Partials       56       58       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@raphaelvallat raphaelvallat added the enhancement 🚧 New feature or request label Mar 29, 2026
@raphaelvallat raphaelvallat added this to the v0.8.0 milestone Mar 29, 2026
@raphaelvallat raphaelvallat merged commit 747d000 into master Mar 29, 2026
18 checks passed
@raphaelvallat raphaelvallat deleted the topoplot_ax branch March 29, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement 🚧 New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ax argument to yasa.topoplot

2 participants