sigma deletes the axis grid

2 views (last 30 days)
Giuseppe Naselli
Giuseppe Naselli on 17 Jul 2019
Edited: Adam Danz on 19 Jul 2019
Hi All,
my code is below
myFigure=figure; % create a figure
ax1 = subplot(231, 'Parent', myFigure,'UserData','my_stuff','nextplot', 'add','XGrid','on','YGrid','on'); % create axix and set grid on in x and y
sigma(ax1,mySystem); % plot
The 2nd line create an axis with grid on, but then with the 3rd line the grid disappears
I can reset the grid back on with a 4th line as
grid(ax1,'on')
however, I was wondering why "sigma" ignore my initial statement in subplot ('XGrid','on','YGrid','on')
Is there a setting in sigma/subplot that I can use?
Thanks
G

Answers (1)

Adam Danz
Adam Danz on 17 Jul 2019
Edited: Adam Danz on 19 Jul 2019
Short answer: You need to add the grid after calling sigma().
Long answer:
Assuming you're using the DynamicSystem method (toolbox \ control \ ctrlanalysis \ @DynamicSystem \ sigma.m), sigma() calls the helper function sigmaplot() which calls ltiplot() which does the plotting.
If "hold on" was not called prior to calling sigma(), the axes are cleared using cla() in ltiplot() as shown below.
% Clear and reset axes if new plot
if NewPlot
% Notify the live editor of newplot
matlab.graphics.internal.clearNotify(ax);
% Clear any existing response plot upfront (otherwise style
% settings below get erased by CLA in respplot/check_hold)
if ~isempty(h)
cla(h.AxesGrid,handle(ax)) % speed optimization
else
cla(ax,'reset')
end
If "hold on" was called prior to calling sigma(), ltiplot() changes a bunch of axes properties. Listed below are the default PlotOptions created in ltiplot() and the changes made to the axis properties.
PlotOptions =
FreqUnits: 'auto'
FreqScale: 'log'
MagUnits: 'dB'
MagScale: 'linear'
IOGrouping: 'none'
InputLabels: [1×1 struct]
OutputLabels: [1×1 struct]
InputVisible: {'on'}
OutputVisible: {'on'}
Title: [1×1 struct]
XLabel: [1×1 struct]
YLabel: [1×1 struct]
TickLabel: [1×1 struct]
Grid: 'off' % <-----
GridColor: [0.15 0.15 0.15]
XLim: {[1 10]}
YLim: {[1 10]}
XLimMode: {'auto'}
YLimMode: {'auto'}
set(ax,...
'XGrid', PlotOptions.Grid,... % <-----
'YGrid', PlotOptions.Grid,... % <-----
'XColor', PlotOptions.TickLabel.Color,...
'YColor', PlotOptions.TickLabel.Color,...
'FontSize', PlotOptions.TickLabel.FontSize,...
'FontWeight', PlotOptions.TickLabel.FontWeight,...
'FontAngle', PlotOptions.TickLabel.FontAngle,...
'Selected', 'off')
So, whether you hold your axes or not, the grids will be cleared. As you've discovered, you can add them back in after calling sigma().

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!