8000 fix bugs in legend generation for pole/zero plots · toaster-code/python-control@acfadf0 · GitHub
[go: up one dir, main page]

Skip to content

Commit acfadf0

Browse files
committed
fix bugs in legend generation for pole/zero plots
1 parent 639ffb4 commit acfadf0

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

control/ctrlplot.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,25 +275,24 @@ def _process_line_labels(label, ntraces, ninputs=0, noutputs=0):
275275

276276
# Get labels for all lines in an axes
277277
def _get_line_labels(ax, use_color=True):
278-
labels, lines = [], []
278+
labels_colors, lines = [], []
279279
last_color, counter = None, 0 # label unknown systems
280280
for i, line in enumerate(ax.get_lines()):
281281
label = line.get_label()
282+
color = line.get_color()
282283
if use_color and label.startswith("Unknown"):
283284
label = f"Unknown-{counter}"
284-
if last_color is None:
285-
last_color = line.get_color()
286-
elif last_color != line.get_color():
285+
if last_color != color:
287286
counter += 1
288-
last_color = line.get_color()
287+
last_color = color
289288
elif label[0] == '_':
290289
continue
291290

292-
if label not in labels:
291+
if (label, color) not in labels_colors:
293292
lines.append(line)
294-
labels.append(label)
293+
labels_colors.append((label, color))
295294

296-
return lines, labels
295+
return lines, [label for label, color in labels_colors]
297296

298297

299298
# Utility function to make legend labels

control/pzmap.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,13 @@ def pole_zero_plot(
391391
real(poles), imag(poles), marker='x', linestyle='',
392392
markeredgecolor=color, markerfacecolor=color,
393393
markersize=marker_size, markeredgewidth=marker_width,
394-
label=label)
394+
color=color, label=label)
395395
if len(zeros) > 0:
396396
out[idx, 1] = ax.plot(
397397
real(zeros), imag(zeros), marker='o', linestyle='',
398398
markeredgecolor=color, markerfacecolor='none',
399-
markersize=marker_size, markeredgewidth=marker_width)
399+
markersize=marker_size, markeredgewidth=marker_width,
400+
color=color)
400401

401402
# Plot the loci, if present
402403
if response.loci is not None:
@@ -447,8 +448,8 @@ def pole_zero_plot(
447448
markeredgecolor=pole_line.get_markerfacecolor(),
448449
markerfacecolor='none', markersize=marker_size,
449450
markeredgewidth=marker_width)
450-
handle = (pole_line, zero_line)
451-
line_tuples.append(handle)
451+
handle = (pole_line, zero_line)
452+
line_tuples.append(handle)
452453

453454
with plt.rc_context(freqplot_rcParams):
454455
legend = ax.legend(

0 commit comments

Comments
 (0)
0