1919
2020from . import config
2121from .bdalg import feedback
22- from .ctrlplot import suptitle , _find_axes_center
22+ from .ctrlplot import suptitle , _find_axes_center , _make_legend_labels , \
23+ _update_suptitle
2324from .ctrlutil import unwrap
2425from .exception import ControlMIMONotImplemented
2526from .frdata import FrequencyResponseData
2627from .lti import LTI , _process_frequency_response , frequency_response
2728from .margins import stability_margins
2829from .statesp import StateSpace
29- from .timeplot import _make_legend_labels
3030from .xferfcn import TransferFunction
3131
3232__all__ = ['bode_plot' , 'NyquistResponseData' , 'nyquist_response' ,
@@ -954,28 +954,7 @@ def gen_zero_centered_series(val_min, val_max, period):
954954 else :
955955 title = data [0 ].title
956956
957- if fig is not None and isinstance (title , str ):
958- # Get the current title, if it exists
959- old_title = None if fig ._suptitle is None else fig ._suptitle ._text
960- new_title = title
961-
962- if old_title is not None :
963- # Find the common part of the titles
964- common_prefix = commonprefix ([old_title , new_title ])
965-
966- # Back up to the last space
967- last_space = common_prefix .rfind (' ' )
968- if last_space > 0 :
969- common_prefix = common_prefix [:last_space ]
970- common_len = len (common_prefix )
971-
972- # Add the new part of the title (usually the system name)
973- if old_title [common_len :] != new_title [common_len :]:
974- separator = ',' if len (common_prefix ) > 0 else ';'
975- new_title = old_title + separator + new_title [common_len :]
976-
977- # Add the title
978- suptitle (title , fig = fig , rcParams = rcParams , frame = suptitle_frame )
957+ _update_suptitle (fig , title , rcParams = rcParams , frame = suptitle_frame )
979958
980959 #
981960 # Create legends
@@ -2717,12 +2696,13 @@ def _get_line_labels(ax, use_color=True):
27172696
27182697
27192698# Turn label keyword into array indexed by trace, output, input
2720- def _process_line_labels (label , nsys , ninputs = 0 , noutputs = 0 ):
2699+ # TODO: move to ctrlutil.py and update parameter names to reflect general use
2700+ def _process_line_labels (label , ntraces , ninputs = 0 , noutputs = 0 ):
27212701 if label is None :
27222702 return None
27232703
27242704 if isinstance (label , str ):
2725- label = [label ]
2705+ label = [label ] * ntraces # single label for all traces
27262706
27272707 # Convert to an ndarray, if not done aleady
27282708 try :
@@ -2734,12 +2714,14 @@ def _process_line_labels(label, nsys, ninputs=0, noutputs=0):
27342714 # TODO: allow more sophisticated broadcasting (and error checking)
27352715 try :
27362716 if ninputs > 0 and noutputs > 0 :
2737- if line_labels .ndim == 1 :
2738- line_labels = line_labels .reshape (nsys , 1 , 1 )
2739- line_labels = np .broadcast_to (
2740- line_labels ,(nsys , ninputs , noutputs ))
2717+ if line_labels .ndim == 1 and line_labels .size == ntraces :
2718+ line_labels = line_labels .reshape (ntraces , 1 , 1 )
2719+ line_labels = np .broadcast_to (
2720+ line_labels , (ntraces , ninputs , noutputs ))
2721+ else :
2722+ line_labels = line_labels .reshape (ntraces , ninputs , noutputs )
27412723 except :
2742- if line_labels .shape [0 ] != nsys :
2724+ if line_labels .shape [0 ] != ntraces :
27432725 raise ValueError ("number of labels must match number of traces" )
27442726 else :
27452727 raise ValueError ("labels must be given for each input/output pair" )
0 commit comments