Skip to content

Commit 8b7d399

Browse files
committed
improve consistency in use of cplt as return type for plots
1 parent acfadf0 commit 8b7d399

12 files changed

Lines changed: 123 additions & 122 deletions

control/ctrlplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ControlPlot(object):
4949
Attributes
5050
----------
5151
lines : array of list of :class:`matplotlib:Line2D`
52-
Array of Line2D objects for each line in the plot. Generally, The
52+
Array of Line2D objects for each line in the plot. Generally, the
5353
shape of the array matches the subplots shape and the value of the
5454
array is a list of Line2D objects in that subplot. Some plotting
5555
functions will return variants of this structure, as described in

control/pzmap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ def _click_dispatcher(event):
503503
else:
504504
TypeError("system lists not supported with legacy return values")
505505

506-
return ControlPlot(out, np.asarray(axs), fig, legend=legend)
506+
return ControlPlot(out, ax, fig, legend=legend)
507507

508508

509509
# Utility function to find gain corresponding to a click event

control/rlocus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ def root_locus_plot(
198198
return responses.loci, responses.gains
199199

200200
# Plot the root loci
201-
ctrlplot = responses.plot(grid=grid, **kwargs)
201+
cplt = responses.plot(grid=grid, **kwargs)
202202

203203
# Legacy processing: return locations of poles and zeros as a tuple
204204
if plot is True:
205205
return responses.loci, responses.gains
206206

207-
return ControlPlot(ctrlplot.lines, ctrlplot.axes, ctrlplot.figure)
207+
return ControlPlot(cplt.lines, cplt.axes, cplt.figure)
208208

209209

210210
def _default_gains(num, den, xlim, ylim):

control/tests/descfcn_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ def test_describing_function_plot():
188188
assert len(response.intersections) == 1
189189
assert len(plt.gcf().get_axes()) == 0 # make sure there is no plot
190190

191-
out = response.plot()
191+
cplt = response.plot()
192192
assert len(plt.gcf().get_axes()) == 1 # make sure there is a plot
193-
assert len(out[0]) == 4 and len(out[1]) == 1
193+
assert len(cplt.lines[0]) == 4 and len(cplt.lines[1]) == 1
194194

195195
# Call plot directly
196-
out = ct.describing_function_plot(H_larger, F_saturation, amp, omega)
197-
assert len(out[0]) == 4 and len(out[1]) == 1
196+
cplt = ct.describing_function_plot(H_larger, F_saturation, amp, omega)
197+
assert len(cplt.lines[0]) == 4 and len(cplt.lines[1]) == 1
198198

199199

200200
def test_describing_function_exceptions():

control/tests/freqplot_test.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ def test_response_plots(
141141
# Use the manaul response to verify that different settings are working
142142
def test_manual_response_limits():
143143
# Default response: limits should be the same across rows
144-
out = manual_response.plot()
145-
axs = ct.get_plot_axes(out)
144+
cplt = manual_response.plot()
145+
axs = ct.get_plot_axes(cplt) # legacy usage OK
146146
for i in range(manual_response.noutputs):
147147
for j in range(1, manual_response.ninputs):
148148
# Everything in the same row should have the same limits
@@ -397,18 +397,18 @@ def test_gangof4_trace_labels():
397397
C = ct.rss(1, 1, 1, name='C')
398398

399399
# Make sure default labels are as expected
400-
out = ct.gangof4_response(P1, C).plot()
401-
out = ct.gangof4_response(P2, C).plot()
402-
axs = ct.get_plot_axes(out)
400+
cplt = ct.gangof4_response(P1, C).plot()
401+
cplt = ct.gangof4_response(P2, C).plot()
402+
axs = ct.get_plot_axes(cplt) # legacy usage OK
403403
legend = axs[0, 1].get_legend().get_texts()
404404
assert legend[0].get_text() == 'None'
405405
assert legend[1].get_text() == 'None'
406406
plt.close()
407407

408408
# Override labels
409-
out = ct.gangof4_response(P1, C).plot(label='xxx, line1, yyy')
410-
out = ct.gangof4_response(P2, C).plot(label='xxx, line2, yyy')
411-
axs = ct.get_plot_axes(out)
409+
cplt = ct.gangof4_response(P1, C).plot(label='xxx, line1, yyy')
410+
cplt = ct.gangof4_response(P2, C).plot(label='xxx, line2, yyy')
411+
axs = ct.get_plot_axes(cplt) # legacy usage OK
412412
legend = axs[0, 1].get_legend().get_texts()
413413
assert legend[0].get_text() == 'xxx, line1, yyy'
414414
assert legend[1].get_text() == 'xxx, line2, yyy'
@@ -426,8 +426,8 @@ def test_freqplot_line_labels(plt_fcn):
426426
ct.set_defaults('freqplot', suptitle_frame='figure')
427427

428428
# Make sure default labels are as expected
429-
out = plt_fcn([sys1, sys2])
430-
axs = ct.get_plot_axes(out)
429+
cplt = plt_fcn([sys1, sys2])
430+
axs = ct.get_plot_axes(cplt) # legacy usage OK
431431
if axs.ndim == 1:
432432
legend = axs[0].get_legend().get_texts()
433433
else:
@@ -437,8 +437,8 @@ def test_freqplot_line_labels(plt_fcn):
437437
plt.close()
438438

439439
# Override labels all at once
440-
out = plt_fcn([sys1, sys2], label=['line1', 'line2'])
441-
axs = ct.get_plot_axes(out)
440+
cplt = plt_fcn([sys1, sys2], label=['line1', 'line2'])
441+
axs = ct.get_plot_axes(cplt) # legacy usage OK
442442
if axs.ndim == 1:
443443
legend = axs[0].get_legend().get_texts()
444444
else:
@@ -448,9 +448,9 @@ def test_freqplot_line_labels(plt_fcn):
448448
plt.close()
449449

450450
# Override labels one at a time
451-
out = plt_fcn(sys1, label='line1')
452-
out = plt_fcn(sys2, label='line2')
453-
axs = ct.get_plot_axes(out)
451+
cplt = plt_fcn(sys1, label='line1')
452+
cplt = plt_fcn(sys2, label='line2')
453+
axs = ct.get_plot_axes(cplt) # legacy usage OK
454454
if axs.ndim == 1:
455455
legend = axs[0].get_legend().get_texts()
456456
else:
@@ -475,8 +475,8 @@ def test_line_labels_bode(kwargs, labels):
475475
with pytest.raises(ValueError, match="number of labels must match"):
476476
ct.bode_plot([sys1, sys2], label=['line1'])
477477

478-
out = ct.bode_plot([sys1, sys2], label=labels, **kwargs)
479-
axs = ct.get_plot_axes(out)
478+
cplt = ct.bode_plot([sys1, sys2], label=labels, **kwargs)
479+
axs = ct.get_plot_axes(cplt) # legacy usage OK
480480
legend_texts = axs[0, -1].get_legend().get_texts()
481481
for i, legend in enumerate(legend_texts):
482482
assert legend.get_text() == labels[i]
@@ -502,22 +502,22 @@ def test_freqplot_ax_keyword(plt_fcn, ninputs, noutputs):
502502
sys = ct.rss(4, ninputs, noutputs)
503503

504504
# Create an initial figure
505-
out1 = plt_fcn(sys)
505+
cplt1 = plt_fcn(sys)
506506

507507
# Draw again on the same figure, using array
508-
axs = ct.get_plot_axes(out1)
509-
out2 = plt_fcn(sys, ax=axs)
510-
np.testing.assert_equal(ct.get_plot_axes(out1), ct.get_plot_axes(out2))
508+
axs = ct.get_plot_axes(cplt1) # legacy usage OK
509+
cplt2 = plt_fcn(sys, ax=axs)
510+
np.testing.assert_equal(cplt1.axes, cplt2.axes)
511511

512512
# Pass things in as a list instead
513513
axs_list = axs.tolist()
514-
out3 = plt_fcn(sys, ax=axs)
515-
np.testing.assert_equal(ct.get_plot_axes(out1), ct.get_plot_axes(out3))
514+
cplt3 = plt_fcn(sys, ax=axs)
515+
np.testing.assert_equal(cplt1.axes, cplt3.axes)
516516

517517
# Flatten the list
518518
axs_list = axs.squeeze().tolist()
519-
out3 = plt_fcn(sys, ax=axs_list)
520-
np.testing.assert_equal(ct.get_plot_axes(out1), ct.get_plot_axes(out3))
519+
cplt4 = plt_fcn(sys, ax=axs_list)
520+
np.testing.assert_equal(cplt1.axes, cplt4.axes)
521521

522522

523523
def test_mixed_systypes():
@@ -552,7 +552,7 @@ def test_suptitle():
552552
sys = ct.rss(2, 2, 2)
553553

554554
# Default location: center of axes
555-
out = ct.bode_plot(sys)
555+
cplt = ct.bode_plot(sys)
556556
assert plt.gcf()._suptitle._x != 0.5
557557

558558
# Try changing the the title

control/tests/nyquist_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,17 +399,17 @@ def test_linestyle_checks():
399399
sys = ct.tf([100], [1, 1, 1])
400400

401401
# Set the line styles
402-
lines = ct.nyquist_plot(
402+
cplt = ct.nyquist_plot(
403403
sys, primary_style=[':', ':'], mirror_style=[':', ':'])
404-
assert all([line.get_linestyle() == ':' for line in lines[0]])
404+
assert all([line.get_linestyle() == ':' for line in cplt.lines[0]])
405405

406406
# Set the line colors
407-
lines = ct.nyquist_plot(sys, color='g')
408-
assert all([line.get_color() == 'g' for line in lines[0]])
407+
cplt = ct.nyquist_plot(sys, color='g')
408+
assert all([line.get_color() == 'g' for line in cplt.lines[0]])
409409

410410
# Turn off the mirror image
411-
lines = ct.nyquist_plot(sys, mirror_style=False)
412-
assert lines[0][2:] == [None, None]
411+
cplt = ct.nyquist_plot(sys, mirror_style=False)
412+
assert cplt.lines[0][2:] == [None, None]
413413

414414
with pytest.raises(ValueError, match="invalid 'primary_style'"):
415415
ct.nyquist_plot(sys, primary_style=False)
@@ -505,7 +505,7 @@ def test_nyquist_frd():
505505

506506
# Computing Nyquist response w/ different frequencies OK if given as a list
507507
nyqresp = ct.nyquist_response([sys1, sys2])
508-
out = nyqresp.plot()
508+
cplt = nyqresp.plot()
509509

510510
warnings.resetwarnings()
511511

control/tests/pzmap_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_pzmap_raises():
119119

120120
def test_pzmap_limits():
121121
sys = ct.tf([1, 2], [1, 2, 3])
122-
out = ct.pole_zero_plot(sys, xlim=[-1, 1], ylim=[-1, 1])
123-
ax = ct.get_plot_axes(out)[0, 0]
122+
cplt = ct.pole_zero_plot(sys, xlim=[-1, 1], ylim=[-1, 1])
123+
ax = cplt.axes[0, 0]
124124
assert ax.get_xlim() == (-1, 1)
125125
assert ax.get_ylim() == (-1, 1)

control/tests/rlocus_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ def test_root_locus_documentation(savefigs=False):
204204

205205
# TODO: generate event in order to generate real title
206206
plt.figure()
207-
out = ct.root_locus_map(sys).plot(initial_gain=3.506)
208-
ax = ct.get_plot_axes(out)[0, 0]
207+
cplt = ct.root_locus_map(sys).plot(initial_gain=3.506)
208+
ax = cplt.axes[0, 0]
209209
freqplot_rcParams = ct.config._get_param('freqplot', 'rcParams')
210210
with plt.rc_context(freqplot_rcParams):
211211
ax.set_title(

0 commit comments

Comments
 (0)