Repository: python-control/python-control

Issue:
Singular values plot not changing colors for list of systems
When the singular values plot is generated for a list of systems, the colors of the lines should be different for each system.  This doesn't seem to be happening.

Example:
```
import control as ct
sys1 = ct.rss(4, 2, 2, strictly_proper=True)
sys2 = ct.rss(4, 2, 2, strictly_proper=True)
ct.singular_values_plot([sys1, sys2])
```
generates

![Image](https://github.com/user-attachments/assets/66f2d7dd-3413-42bd-a3cf-e007676a69a6)

The following code works correctly in terms of colors:
```
ct.singular_values_plot(sys1)
ct.singular_values_plot(sys2)
```

![Image](https://github.com/user-attachments/assets/8b589767-463f-4793-8276-432058588811)

Note that the range of frequencies is different for each system, which is the reason you want to be able to call them as a list.


Discussion:

Patch:
diff --git a/control/freqplot.py b/control/freqplot.py
index fe258d636..048979960 100644
--- a/control/freqplot.py
+++ b/control/freqplot.py
@@ -2556,12 +2556,12 @@ def singular_values_plot(
             nyq_freq = None
 
         # Determine the color to use for this response
-        color = _get_color(
+        current_color = _get_color(
             color, fmt=fmt, offset=color_offset + idx_sys,
             color_cycle=color_cycle)
 
         # To avoid conflict with *fmt, only pass color kw if non-None
-        color_arg = {} if color is None else {'color': color}
+        color_arg = {} if current_color is None else {'color': current_color}
 
         # Decide on the system name
         sysname = response.sysname if response.sysname is not None \


Test patch:
diff --git a/control/tests/freqplot_test.py b/control/tests/freqplot_test.py
index c0dfa4030..b3770486c 100644
--- a/control/tests/freqplot_test.py
+++ b/control/tests/freqplot_test.py
@@ -680,6 +680,39 @@ def test_display_margins(nsys, display_margins, gridkw, match):
         assert cplt.axes[0, 0].get_title() == ''
 
 
+def test_singular_values_plot_colors():
+    # Define some systems for testing
+    sys1 = ct.rss(4, 2, 2, strictly_proper=True)
+    sys2 = ct.rss(4, 2, 2, strictly_proper=True)
+
+    # Get the default color cycle
+    color_cycle = plt.rcParams['axes.prop_cycle'].by_key()['color']
+
+    # Plot the systems individually and make sure line colors are OK
+    cplt = ct.singular_values_plot(sys1)
+    assert cplt.lines.size == 1
+    assert len(cplt.lines[0]) == 2
+    assert cplt.lines[0][0].get_color() == color_cycle[0]
+    assert cplt.lines[0][1].get_color() == color_cycle[0]
+
+    cplt = ct.singular_values_plot(sys2)
+    assert cplt.lines.size == 1
+    assert len(cplt.lines[0]) == 2
+    assert cplt.lines[0][0].get_color() == color_cycle[1]
+    assert cplt.lines[0][1].get_color() == color_cycle[1]
+    plt.close('all')
+
+    # Plot the systems as a list and make sure colors are OK
+    cplt = ct.singular_values_plot([sys1, sys2])
+    assert cplt.lines.size == 2
+    assert len(cplt.lines[0]) == 2
+    assert len(cplt.lines[1]) == 2
+    assert cplt.lines[0][0].get_color() == color_cycle[0]
+    assert cplt.lines[0][1].get_color() == color_cycle[0]
+    assert cplt.lines[1][0].get_color() == color_cycle[1]
+    assert cplt.lines[1][1].get_color() == color_cycle[1]
+
+
 if __name__ == "__main__":
     #
     # Interactive mode: generate plots for manual viewing