-
Notifications
You must be signed in to change notification settings - Fork 438
Frequency plot improvements #1011
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
Merged
murrayrm
merged 18 commits into
python-control:main
from
murrayrm:freqresp_improvements-16Apr2024
Jun 29, 2024
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b9acc99
allow label keyword in bode_plot() to override default labels
murrayrm 0b6348f
add label keyword to singular_value_plot and nyquist_plot
murrayrm 606cf48
add additional tests for freqplot label override + small fixes
murrayrm 5e405cc
don't strip common parts of labels if given explicitly
murrayrm eeebec3
BUG: indent_radius not handled properly when passed to nyquist_plot
murrayrm 402b45f
restore [wmin, wmax] functionality + documentation updates
murrayrm 6f6c70d
refactoring/regularization of ax keyword processing
murrayrm 404fbdf
regularize processing of rcParams
murrayrm 1a94f4e
add suptitle() function for better centered titles
murrayrm 28995f1
updated freqplot documentation + figures
murrayrm ffb0a0f
move plotutil to ctrlplot
murrayrm 4734912
update freq_label handling + add Bode/Nyquist notebook
murrayrm aeb187f
set up frd() as full factory function for FRD I/Osystems
murrayrm ddb5b7c
update unexpected keyword check for GitHub action variation
murrayrm 2fde963
allowed Bode/Nyquist for mixed FRD systems
murrayrm b7c158b
update CDS 110 example
murrayrm 59a676e
fix typos in doc, docstrings pointed out by @slivingston review
murrayrm 343df2c
fix issues in examples/cds110_bode-nyquist.ipynb per @slivingston review
murrayrm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# ctrlplot.py - utility functions for plotting | ||
# Richard M. Murray, 14 Jun 2024 | ||
# | ||
# Collection of functions that are used by various plotting functions. | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
from . import config | ||
|
||
__all__ = ['suptitle'] | ||
|
||
|
||
def suptitle( | ||
title, fig=None, frame='axes', **kwargs): | ||
"""Add a centered title to a figure. | ||
|
||
This is a wrapper for the matplotlib `suptitle` function, but by | ||
setting ``frame`` to 'axes' (default) then the title is centered on the | ||
midpoint of the axes in the figure, rather than the center of the | ||
figure. This usually looks better (particularly with multi-panel | ||
plots), though it takes longer to render. | ||
|
||
Parameters | ||
---------- | ||
title : str | ||
Title text. | ||
fig : Figure, optional | ||
Matplotlib figure. Defaults to current figure. | ||
frame : str, optional | ||
Coordinate frame to use for centering: 'axes' (default) or 'figure'. | ||
**kwargs : :func:`matplotlib.pyplot.suptitle` keywords, optional | ||
Additional keywords (passed to matplotlib). | ||
|
||
""" | ||
rcParams = config._get_param('freqplot', 'rcParams', kwargs, pop=True) | ||
|
||
if fig is None: | ||
fig = plt.gcf() | ||
|
||
if frame == 'figure': | ||
with plt.rc_context(rcParams): | ||
fig.suptitle(title, **kwargs) | ||
|
||
elif frame == 'axes': | ||
# TODO: move common plotting params to 'ctrlplot' | ||
rcParams = config._get_param('freqplot', 'rcParams', rcParams) | ||
with plt.rc_context(rcParams): | ||
plt.tight_layout() # Put the figure into proper layout | ||
xc, _ = _find_axes_center(fig, fig.get_axes()) | ||
|
||
fig.suptitle(title, x=xc, **kwargs) | ||
plt.tight_layout() # Update the layout | ||
|
||
else: | ||
raise ValueError(f"unknown frame '{frame}'") | ||
|
||
|
||
def _find_axes_center(fig, axs): | ||
"""Find the midpoint between axes in display coordinates. | ||
|
||
This function finds the middle of a plot as defined by a set of axes. | ||
|
||
""" | ||
inv_transform = fig.transFigure.inverted() | ||
xlim = ylim = [1, 0] | ||
for ax in axs: | ||
ll = inv_transform.transform(ax.transAxes.transform((0, 0))) | ||
ur = inv_transform.transform(ax.transAxes.transform((1, 1))) | ||
|
||
xlim = [min(ll[0], xlim[0]), max(ur[0], xlim[1])] | ||
ylim = [min(ll[1], ylim[0]), max(ur[1], ylim[1])] | ||
|
||
return (np.sum(xlim)/2, np.sum(ylim)/2) |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This same TODO comment is already freqplot.py, and it is not clear what the comment means here (in ctrlplot). Should the TODO comment be deleted here in favor of the one in freqplot.py ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading it again, I think this TODO comment is to be able to
If so, then I understand the motivation, and OK to keep both TODO comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got another PR coming that will address both TODOs. Doing things in stages so that everything is in (slightly) smaller chunks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. I am almost done reviewing this one.