|
12 | 12 | import matplotlib as mpl
|
13 | 13 | import matplotlib.pyplot as plt
|
14 | 14 | from os.path import commonprefix
|
| 15 | +from warnings import warn |
15 | 16 |
|
16 | 17 | from . import config
|
17 | 18 |
|
@@ -48,7 +49,7 @@ def time_response_plot(
|
48 | 49 | transpose=False, overlay_traces=False, overlay_signals=False,
|
49 | 50 | legend_map=None, legend_loc=None, add_initial_zero=True,
|
50 | 51 | input_props=None, output_props=None, trace_props=None,
|
51 |
| - title=None, relabel=True, **kwargs): |
| 52 | + trace_labels=None, title=None, relabel=True, **kwargs): |
52 | 53 | """Plot the time response of an input/output system.
|
53 | 54 |
|
54 | 55 | This function creates a standard set of plots for the input/output
|
@@ -161,14 +162,20 @@ def time_response_plot(
|
161 | 162 | time_label = config._get_param(
|
162 | 163 | 'timeplot', 'time_label', kwargs, _timeplot_defaults, pop=True)
|
163 | 164 |
|
| 165 | + if input_props and len(fmt) > 0: |
| 166 | + warn("input_props ignored since fmt string was present") |
164 | 167 | input_props = config._get_param(
|
165 | 168 | 'timeplot', 'input_props', kwargs, _timeplot_defaults, pop=True)
|
166 | 169 | iprop_len = len(input_props)
|
167 | 170 |
|
| 171 | + if output_props and len(fmt) > 0: |
| 172 | + warn("output_props ignored since fmt string was present") |
168 | 173 | output_props = config._get_param(
|
169 | 174 | 'timeplot', 'output_props', kwargs, _timeplot_defaults, pop=True)
|
170 | 175 | oprop_len = len(output_props)
|
171 | 176 |
|
| 177 | + if trace_props and len(fmt) > 0: |
| 178 | + warn("trace_props ignored since fmt string was present") |
172 | 179 | trace_props = config._get_param(
|
173 | 180 | 'timeplot', 'trace_props', kwargs, _timeplot_defaults, pop=True)
|
174 | 181 | tprop_len = len(trace_props)
|
@@ -365,10 +372,14 @@ def _make_line_label(signal_index, signal_labels, trace_index):
|
365 | 372 | label += signal_labels[signal_index]
|
366 | 373 |
|
367 | 374 | # Add the trace label if this is a multi-trace figure
|
368 |
| - if overlay_traces and ntraces > 1: |
| 375 | + if overlay_traces and ntraces > 1 or trace_labels: |
369 | 376 | label += ", " if label != "" else ""
|
370 |
| - label += f"trace {trace_index}" if data.trace_labels is None \ |
371 |
| - else data.trace_labels[trace_index] |
| 377 | + if trace_labels: |
| 378 | + label += trace_labels[trace_index] |
| 379 | + elif data.trace_labels: |
| 380 | + label += data.trace_labels[trace_index] |
| 381 | + else: |
| 382 | + label += f"trace {trace_index}" |
372 | 383 |
|
373 | 384 | # Add the system name (will strip off later if redundant)
|
374 | 385 | label += ", " if label != "" else ""
|
@@ -471,18 +482,28 @@ def _make_line_label(signal_index, signal_labels, trace_index):
|
471 | 482 | label = ax_array[trace, 0].get_ylabel()
|
472 | 483 |
|
473 | 484 | # Add on the trace title
|
474 |
| - label = f"Trace {trace}" if data.trace_labels is None \ |
475 |
| - else data.trace_labels[trace] + "\n" + label |
| 485 | + if trace_labels: |
| 486 | + label = trace_labels[trace] + "\n" + label |
| 487 | + elif data.trace_labels: |
| 488 | + label = data.trace_labels[trace] + "\n" + label |
| 489 | + else: |
| 490 | + label = f"Trace {trace}" + "\n" + label |
| 491 | + |
476 | 492 | ax_array[trace, 0].set_ylabel(label)
|
477 | 493 |
|
478 | 494 | else: # regular plot (outputs over inputs)
|
479 | 495 | # Set the trace titles, if needed
|
480 | 496 | if ntraces > 1 and not overlay_traces:
|
481 | 497 | for trace in range(ntraces):
|
| 498 | + if trace_labels: |
| 499 | + label = trace_labels[trace] |
| 500 | + elif data.trace_labels: |
| 501 | + label = data.trace_labels[trace] |
| 502 | + else: |
| 503 | + label = f"Trace {trace}" |
| 504 | + |
482 | 505 | with plt.rc_context(_timeplot_rcParams):
|
483 |
| - ax_array[0, trace].set_title( |
484 |
| - f"Trace {trace}" if data.trace_labels is None |
485 |
| - else data.trace_labels[trace]) |
| 506 | + ax_array[0, trace].set_title(label) |
486 | 507 |
|
487 | 508 | # Label the outputs
|
488 | 509 | if overlay_signals and plot_outputs:
|
@@ -622,22 +643,22 @@ def _make_line_label(signal_index, signal_labels, trace_index):
|
622 | 643 | if fig is not None and title is not None:
|
623 | 644 | # Get the current title, if it exists
|
624 | 645 | old_title = None if fig._suptitle is None else fig._suptitle._text
|
| 646 | + new_title = title |
625 | 647 |
|
626 | 648 | if old_title is not None:
|
627 | 649 | # Find the common part of the titles
|
628 |
| - common_prefix = commonprefix([old_title, title]) |
| 650 | + common_prefix = commonprefix([old_title, new_title]) |
629 | 651 |
|
630 | 652 | # Back up to the last space
|
631 | 653 | last_space = common_prefix.rfind(' ')
|
632 | 654 | if last_space > 0:
|
633 | 655 | common_prefix = common_prefix[:last_space]
|
634 |
| - title_suffix = title[len(common_prefix):] |
| 656 | + common_len = len(common_prefix) |
635 | 657 |
|
636 | 658 | # Add the new part of the title (usually the system name)
|
637 |
| - separator = ',' if len(common_prefix) > 0 else ';' |
638 |
| - new_title = old_title + separator + title_suffix |
639 |
| - else: |
640 |
| - new_title = title |
| 659 | + if old_title[common_len:] != new_title[common_len:]: |
| 660 | + separator = ',' if len(common_prefix) > 0 else ';' |
| 661 | + new_title = old_title + separator + new_title[common_len:] |
641 | 662 |
|
642 | 663 | # Add the title
|
643 | 664 | with plt.rc_context(_timeplot_rcParams):
|
|
0 commit comments