function opt = iddataPlotOptions(Type, p)
% iddataPlotOptions Options for the iddata/plot command.
%
% OPT_TIME = iddataPlotOptions('time') creates a default option set for
% plotting time domain data. The list of options in OPT_TIME allows you to
% customize the plot appearance from the command line. You can pass it as
% an input argument to the IDDATA/PLOT command.
%
% OPT_FREQ = iddataPlotOptions('frequency') creates a default option set
% for plotting frequency domain data.
%
% iddataPlotOptions(...,'identpref') initializes the plot options with the
% System Identification Toolbox preferences.
%
% For OPT_TIME, available options include:
%      Title, XLabel, YLabel         Label text and style
%      TickLabel                     Tick label style
%      Grid                          Show or hide the grid [{off}|on]
%      GridColor                     Color of grid lines. Default:[0.15 0.15 0.15]
%      XlimMode, YlimMode            Limit modes
%      Xlim, Ylim                    Axes limits
%      IOGrouping                    Grouping of data channels:
%                                    [{none}|all] 
%      InputLabels, OutputLabels     Input and output label styles
%      InputVisible, OutputVisible   Visibility of input and output channels
%      Orientation                   Arrange IO axes in various ways.
%                                    [{two-row}|two-column|one-row|one-column]                              
%      TimeUnits                     Time units                                    
%      Normalize                     Normalize repsonses [on|{off}]
%      InputInterSample              Intersample behavior of the input signals, 
%                                    which influences the simulation and prediction
%                                    of continuous-time models. 
%
% For OPT_FREQ, available options include:
%      Title, XLabel, YLabel         Label text and style
%      TickLabel                     Tick label style
%      Grid                          Show or hide the grid [{off}|on]
%      GridColor                     Color of grid lines. Default:[0.15 0.15 0.15]
%      XlimMode, YlimMode            Limit modes
%      Xlim, Ylim                    Axes limits
%      IOGrouping                    Grouping of data channels
%                                    [{none}|all] 
%      InputLabels, OutputLabels     Input and output label styles
%      InputVisible, OutputVisible   Visibility of input and output channels
%      FreqUnits                     Frequency units
%      FreqScale                     Frequency scale [linear|{log}]
%      MagUnits                      Magnitude units [dB|{abs}]
%      MagScale                      Magnitude scale [{linear}|log]
%      MagVisible                    Magnitude plot visibility [{on}|off]
%      MagLowerLimMode               Enables a lower magnitude limit [{auto}|manual]
%      MagLowerLim                   Specifies the lower magnitude limit
%      PhaseUnits                    Phase units [{deg}|rad]
%      PhaseVisible                  Phase plot visibility [{on}|off]
%      PhaseWrapping                 Enables phase wrapping [on|{off}]
%      PhaseMatching                 Enables phase matching [on|{off}]
%      PhaseMatchingFreq             Frequency for matching phase
%      PhaseMatchingValue            The value to make the phase response close to
%      Orientation                   Arrange IO axes in various ways.
%                                    [{two-row}|two-column|one-row|one-column] 
%
% Example: Time plot configuration.
%         opt = iddataPlotOptions('time');
%         % View the plot in minutes time units.
%         opt.TimeUnits = 'minutes';
%         % Turn grid on
%         opt.Grid = 'on';
%         % Create plot with the options specified by opt:
%         load iddata1 z1
%         h = plot(z1, opt);
%
% Example: Frequency plot configuration.        
%         opt = iddataPlotOptions('frequency');
%         % Set phase visibility to off and frequency units to Hz in options 
%         opt.PhaseVisible = 'off'; 
%         opt.FreqUnits = 'Hz'; 
%         % Create plot with the options specified by opt:
%         load iddata7 z7
%         zf = fft(z7);
%         h = plot(zf, opt);
%
% See also iddata/plot, wrfc.getoptions, wrfc.setoptions, identpref.

%   Copyright 2013-2017 The MathWorks, Inc.
narginchk(1,2)
ni = nargin;
Type = ltipack.matchKey(Type, {'time','frequency'});
if isempty(Type)
   error(message('Ident:plots:iddataplotoptions1'))
end
if ni==2 && ((~ischar(p) && ~isstring(p)) || ~strcmpi(p,'identpref'))
   error(message('Ident:plots:iddataplotoptions2'))
end

if strcmp(Type,'time')
   opt = plotopts.IOTimePlotOptions;
else
   opt = plotopts.IOFrequencyPlotOptions;
   opt.Title.String = getString(message('Controllib:plots:strIOData'));
end

if ni==2
   opt.mapCSTPrefs();
end
