Skip to content

Commit

Permalink
Fixes live plot issue (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenNneji authored Jul 12, 2024
1 parent 55fec6e commit 72d9879
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
14 changes: 9 additions & 5 deletions utilities/plotting/plotRefSLDHelper.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
function plotRefSLDHelper(data, noDelay, figureId)
function plotRefSLDHelper(data, noDelay)
% Helper function to make it easier to plot from event. Data is a struct
% with the plot data and noDelay indicates if draw should be delayed.
%
% plotRefSLDHelper(data, false, 1);
% plotRefSLDHelper(data, false);
arguments
data
noDelay {logical} = true
figureId {mustBeInteger} = 0
end
if figureId > 0
figure(figureId);

defaultState = 'on';
s = warning();
if any(strcmp({s.identifier}, 'MATLAB:Axes:NegativeDataInLogAxis'))
defaultState = 'off';
end
warning('off','MATLAB:Axes:NegativeDataInLogAxis');

numberOfContrasts = length(data.reflectivity);

Expand Down Expand Up @@ -76,4 +79,5 @@ function plotRefSLDHelper(data, noDelay, figureId)
if noDelay
drawnow limitrate;
end
warning(defaultState, 'MATLAB:Axes:NegativeDataInLogAxis');
end
17 changes: 13 additions & 4 deletions utilities/plotting/useLivePlot.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
figureId {mustBePositive, mustBeInteger} = 1000
end
obj.figureId = figureId;
obj.handle = @(varargin) obj.callback(varargin{:}, true, obj.figureId);
obj.handle = @(varargin) obj.updatePlot(varargin{:});
% Make the figure
h = figure(obj.figureId);
% Unregister other live plots only one at a time
Expand All @@ -30,12 +30,21 @@
'set controls.calcSldDuringFit = true\n'], figureId);
end

function updatePlot(obj, data)
% Clears axes and updates plot
figure(obj.figureId);
subplot(1, 2, 1); cla;
subplot(1, 2, 2); cla;
obj.callback(data, false);
end

function closeFigure(obj)
% Safely close the updating figure and clear the event...
% Remove all events...
% Safely close the updating figure and clear the event.

% Removes event for this plot
eventManager.unregister(eventTypes.Plot, obj.handle);

% close the figure....
% close the figure.
delete(obj.figureId);
end
end
Expand Down

0 comments on commit 72d9879

Please sign in to comment.