Skip to content

Allow setting frequency units for psd plots - #32211

Open
cdholmes wants to merge 2 commits into
matplotlib:mainfrom
cdholmes:psd_units
Open

Allow setting frequency units for psd plots#32211
cdholmes wants to merge 2 commits into
matplotlib:mainfrom
cdholmes:psd_units

Conversation

@cdholmes

@cdholmes cdholmes commented Aug 14, 2026

Copy link
Copy Markdown

PR summary

This PR allows users to specify the units for the sampling frequency in power spectral density (psd) plots. psd previously assumed units to be Hz and displayed Hz on the y-axis label. Users can now specify other units with the Funits keyword. If the keyword is omitted, Hz is assumed by default, so the change is backward compatible. This change has no effect on the psd calculation, only the resulting plot.

AI Disclosure

No AI was used

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • New and changed code is tested
  • Plotting related features are demonstrated in an example
  • New features and API changes have release notes
  • Documentation complies with general and docstring guidelines

In psd, allow user to specify the units for the sampling frequency of the analyzed array. psd previously assumed units to be Hz and displayed this on the y-axis label. Users can now specify other units. This change has no effect on the psd calculation.
@github-actions

Copy link
Copy Markdown

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process.

You can also join us on discourse chat for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@cdholmes
cdholmes marked this pull request as draft August 15, 2026 00:11
@cdholmes
cdholmes marked this pull request as ready for review August 15, 2026 01:02

@scottshambaugh scottshambaugh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One comment to avoid an API break, but I think this looks pretty good and is a nice quality-of-life improvement.

@_preprocess_data(replace_names=["x"])
@_docstring.interpd
def psd(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
def psd(self, x, NFFT=None, Fs=None, Funits=None, Fc=None, detrend=None,

@scottshambaugh scottshambaugh Aug 15, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should go right before **kwargs so that it doesn't break current positional arguments. And then update the positions below as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants