function redrawAxesD(hobject,eventdata,Empty_Button,AxesD,lcs,LCS)
data = get(Empty_Button,'UserData');

if data.isbd
    if data.ifir<data.ilas
        xbd(2) = data.ifir;
        xbd(1) = data.ilas;

        xl = get(AxesD,'xlim');
        yl = get(AxesD,'ylim');

        if isfield(data, 'noc') ~= 1
            data.noc = 0;
        end

        lc = lcs(mod(data.noc,size(lcs,1))+1,:);
        lcf = LCS(mod(data.noc,size(lcs,1))+1,:);

        axes(AxesD);
        fill(data.x(xbd([1 2 2 1 1])), data.yl([1 1 2 2 1]), lcf);
        hold(AxesD,'on')
        set(AxesD, 'xlim', xl, 'ylim', yl);
        xlabel(AxesD,'channel');
    end
elseif data.isautodetect
    mid = min(0,min(min(data.D)));
    mad = max(max(data.D))*1.1;
    lgntxt = {};
    length(data.autodetect)
    for i=1:length(data.autodetect)
        plot(AxesD,data.x(data.autodetect(i))*[1 1],[mid mad],'linewidth',1.5)
        hold(AxesD, 'on');
        lgntxt{end+1} = num2str(round(10*data.x(data.autodetect(i)))/10);
    end
%     plot(AxesD,data.x,data.D','k');
%     axis(AxesD,'tight');
%     set(AxesD,'ylim',[mid mad]);
%     xlabel(AxesD,'channel');
else

    text(AxesD,0.5,0.7,data.peakhint,'Color',[1 0.7 0.6],'FontSize',18,'Units','normalized','HorizontalAlignment', 'center');
    hold(AxesD,"on")
end

if isfield(data,'id')
    id = data.id;
else
    id = 1:length(data.x);
end

if data.isdata
    plot(AxesD,data.x(id),data.D(:,id)','k');
    axis(AxesD,'tight');
%     yl = get(AxesD,'ylim');
    yl = [min(min(data.D)), max(max(data.D))];
    yl = [min(0,yl(1)), yl(2)*1.1];
    set(AxesD,'ylim',yl);
    xlabel(AxesD,'channel');

    if data.isautodetect
        lgn = legend(AxesD,lgntxt);
        set(lgn,'fontsize',12,'location','best');
    end
end

hold(AxesD, 'off');