8000 Merge pull request #1138 from lkies/fix-svp · python-control/python-control@ad996f9 · GitHub
[go: up one dir, main page]

Skip to content

Commit ad996f9

Browse files
authored
Merge pull request #1138 from lkies/fix-svp
Fix color cycling not working in singular_values_plot
2 parents 45a6a2a + 049a716 commit ad996f9

File tree

2 files changed

+35
-2
lines changed
Filter options

2 files changed

+35
-2
lines changed

control/freqplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,12 +2556,12 @@ def singular_values_plot(
25562556
nyq_freq = None
25572557

25582558
# Determine the color to use for this response
2559-
color = _get_color(
2559+
current_color = _get_color(
25602560
color, fmt=fmt, offset=color_offset + idx_sys,
25612561
color_cycle=color_cycle)
25622562

25632563
# To avoid conflict with *fmt, only pass color kw if non-None
2564-
color_arg = {} if color is None else {'color': color}
2564+
color_arg = {} if current_color is None else {'color': current_color}
25652565

25662566
# Decide on the system name
25672567
sysname = response.sysname if response.sysname is not None \

control/tests/freqplot_test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,39 @@ def test_display_margins(nsys, display_margins, gridkw, match):
680680
assert cplt.axes[0, 0].get_title() == ''
681681

682682

683+
def test_singular_values_plot_colors():
684+
# Define some systems for testing
685+
sys1 = ct.rss(4, 2, 2, strictly_proper=True)
686+
sys2 = ct.rss(4, 2, 2, strictly_proper=True)
687+
688+
# Get the default color cycle
689+
color_cycle = plt.rcParams['axes.prop_cycle'].by_key()['color']
690+
691+
# Plot the systems individually and make sure line colors are OK
692+
cplt = ct.singular_values_plot(sys1)
693+
assert cplt.lines.size == 1
694+
assert len(cplt.lines[0]) == 2
695+
assert cplt.lines[0][0].get_color() == color_cycle[0]
696+
assert cplt.lines[0][1].get_color() == color_cycle[0]
697+
698+
cplt = ct.singular_values_plot(sys2)
699+
assert cplt.lines.size == 1
700+
assert len(cplt.lines[0]) == 2
701+
assert cplt.lines[0][0].get_color() == color_cycle[1]
702+
assert cplt.lines[0][1].get_color() == color_cycle[1]
703+
plt.close('all')
704+
705+
# Plot the systems as a list and make sure colors are OK
706+
cplt = ct.singular_values_plot([sys1, sys2])
707+
assert cplt.lines.size == 2
708+
assert len(cplt.lines[0]) == 2
709+
assert len(cplt.lines[1]) == 2
710+
assert cplt.lines[0][0].get_color() == color_cycle[0]
711+
assert cplt.lines[0][1].get_color() == color_cycle[0]
712+
assert cplt.lines[1][0].get_color() == color_cycle[1]
713+
assert cplt.lines[1][1].get_color() == color_cycle[1]
714+
715+
683716
if __name__ == "__main__":
684717
#
685718
# Interactive mode: generate plots for manual viewing

0 commit comments

Comments
 (0)
0