Skip to content

LivePlot should update not overplot... #243

@arwelHughes

Description

@arwelHughes

As the title! :)

Rather than plotting everything on top of the previous plots, LivePlot should clear the axes first so that the update is clear.
The mod below works, but may not be the best way....

`classdef useLivePlot < handle
% Sets up a live plot on a given figure
properties
figureId
handle
end

properties (Constant)
    callback = @plotUpdateWrapper; %@plotRefSLDHelper
end

methods
    function obj = useLivePlot(figureId)
        arguments
            figureId {mustBePositive, mustBeInteger} = 1000
        end
        obj.figureId = figureId;
        obj.handle = @(varargin) obj.callback(varargin{:}, true, obj.figureId);
        % Make the figure
        h = figure(obj.figureId);
        % Unregister other live plots only one at a time
        eventManager.clear(eventTypes.Plot)
        % Register the event
        eventManager.register(eventTypes.Plot, obj.handle);
        
        % Register the close function with the figure
        set(h,'CloseRequestFcn', @(varargin) obj.closeFigure());
        
        fprintf(['Live updating plot started in figure %d.\n To ensure slds are plotted, ' ...
                 'set controls.calcSldDuringFit = true\n'], figureId);

        warning('off','MATLAB:Axes:NegativeDataInLogAxis');
    end
    
    function closeFigure(obj)
        % Safely close the updating figure and clear the event...
        % Remove all events...
        eventManager.unregister(eventTypes.Plot, obj.handle);
        
        % close the figure....
        delete(obj.figureId);
    end
end

end

function plotUpdateWrapper(varargin)

figure(1);
subplot(1,2,1); cla
subplot(1,2,2); cla

plotRefSLDHelper(varargin{:});

%drawnow limitrate

end`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions