-
Notifications
You must be signed in to change notification settings - Fork 440
recalculate loci for sisotool and rlocus on axis scaling #1153
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -22,6 +22,7 @@ | |||||||||||||||||
from .statesp import ss, summing_junction | ||||||||||||||||||
from .timeresp import step_response | ||||||||||||||||||
from .xferfcn import tf | ||||||||||||||||||
from .rlocus import add_loci_recalculate | ||||||||||||||||||
|
||||||||||||||||||
_sisotool_defaults = { | ||||||||||||||||||
'sisotool.initial_gain': 1 | ||||||||||||||||||
|
@@ -105,7 +106,7 @@ def sisotool(sys, initial_gain=None, xlim_rlocus=None, ylim_rlocus=None, | |||||||||||||||||
fig = plt.gcf() | ||||||||||||||||||
if fig.canvas.manager.get_window_title() != 'Sisotool': | ||||||||||||||||||
plt.close(fig) | ||||||||||||||||||
fig,axes = plt.subplots(2, 2) | ||||||||||||||||||
fig, axes = plt.subplots(2, 2) | ||||||||||||||||||
fig.canvas.manager.set_window_title('Sisotool') | ||||||||||||||||||
else: | ||||||||||||||||||
axes = np.array(fig.get_axes()).reshape(2, 2) | ||||||||||||||||||
|
@@ -137,15 +138,18 @@ def sisotool(sys, initial_gain=None, xlim_rlocus=None, ylim_rlocus=None, | |||||||||||||||||
# sys[0, 0], initial_gain=initial_gain, xlim=xlim_rlocus, | ||||||||||||||||||
# ylim=ylim_rlocus, plotstr=plotstr_rlocus, grid=rlocus_grid, | ||||||||||||||||||
# ax=fig.axes[1]) | ||||||||||||||||||
ax_rlocus = fig.axes[1] | ||||||||||||||||||
root_locus_map(sys[0, 0]).plot( | ||||||||||||||||||
ax_rlocus = axes[0,1] # fig.axes[1] | ||||||||||||||||||
cplt = root_locus_map(sys[0, 0]).plot( | ||||||||||||||||||
xlim=xlim_rlocus, ylim=ylim_rlocus, | ||||||||||||||||||
initial_gain=initial_gain, ax=ax_rlocus) | ||||||||||||||||||
if rlocus_grid is False: | ||||||||||||||||||
# Need to generate grid manually, since root_locus_plot() won't | ||||||||||||||||||
from .grid import nogrid | ||||||||||||||||||
nogrid(sys.dt, ax=ax_rlocus) | ||||||||||||||||||
|
||||||||||||||||||
# install a zoom callback on the root-locus axis | ||||||||||||||||||
add_loci_recalculate(sys, cplt, ax_rlocus) | ||||||||||||||||||
|
||||||||||||||||||
# Reset the button release callback so that we can update all plots | ||||||||||||||||||
fig.canvas.mpl_connect( | ||||||||||||||||||
'button_release_event', partial( | ||||||||||||||||||
|
@@ -155,9 +159,8 @@ def sisotool(sys, initial_gain=None, xlim_rlocus=None, ylim_rlocus=None, | |||||||||||||||||
|
||||||||||||||||||
def _click_dispatcher(event, sys, ax, bode_plot_params, tvect): | ||||||||||||||||||
# Zoom handled by specialized callback in rlocus, only handle gain plot | ||||||||||||||||||
if event.inaxes == ax.axes and \ | ||||||||||||||||||
plt.get_current_fig_manager().toolbar.mode not in \ | ||||||||||||||||||
{'zoom rect', 'pan/zoom'}: | ||||||||||||||||||
if event.inaxes == ax.axes: | ||||||||||||||||||
|
||||||||||||||||||
fig = ax.figure | ||||||||||||||||||
|
||||||||||||||||||
Comment on lines
+162
to
165
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The original toolbar mode check for
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my experience, the risk of interpreting a click as a valid gain selection is small, and in my testing (with a print statement indicating when the callback is invoked), the zoom and pan events did not propagate to this callback. Removing the zoom_rect and pan/zoom check also removes unintended mode change (updating of the remaining 3 plots is inhibited when zoom / pan is selected), which can be confusing to users. |
||||||||||||||||||
# if a point is clicked on the rootlocus plot visually emphasize it | ||||||||||||||||||
|
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.
[nitpick] Recalculating the entire locus on every
xlim
/ylim
change can be expensive. Consider debouncing these callbacks or limiting the update frequency during continuous zooming.Copilot uses AI. Check for mistakes.
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 was no issue when interacting with the root-locus plot. Default number of points calculate is a measly 50, with the adaptive code in
_default_gains
typically a maximum between 100 and 200 points was produced. The callback will not be activated when the user manually specifies the gains.