function PlotModel(handles,colour)

if get(handles.overlaybutton,'value')==1
    hold on
else
    hold off
    PlotData(handles)
    hold on
end

if handles.fitspecs.havefit == 1
    
    data = handles.fitspecs.data;
    model = handles.model;
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Show suggested fit
    axes(handles.pdfaxes)
    hold on
    % Find a suitable range to display model PDF over
    mn = min(data); mx = max(data);
    v=[0: (mx-mn)/1000: mx-mn] + mn;
    tmpPDF = BinomPDF(model,v);
    tmpmx = max(tmpPDF);
    increment = 0.01 * std(data);
    j=0;
    while BinomPDF(model,mn) > 1e-3*tmpmx & j<1e6
        mn = mn - increment;
        j=j+1;
    end
    j=0;
    while BinomPDF(model,mx) > 1e-3*tmpmx & j<1e6
        mx = mx + increment;
        j=j+1;
    end
    
    v=[0: (mx-mn)/1000: mx-mn] + mn;
    
    tmpPDF = BinomPDF(model,v);
    tmpmx = max(tmpPDF);
    plot(v,tmpPDF,colour,'linewidth',handles.fitspecs.lw)
    
    % Also draw on PDF ignoring glitches, for comparison:
    if isfield(model,'glitchrate') && model.glitchrate>0
        % See what PDF looks like with no glitches:
        tmpmodel=model;
        tmpmodel.glitchrate=0;
        tmpPDF2 = BinomPDF(tmpmodel,v);
        plot(v,tmpPDF2,'m','linewidth',handles.fitspecs.lw,'linest',':')
    end        
    
    % CHoose y axis approprpately
    axis tight
    tmp = get(gca,'ylim');
    mxy = tmp(2);
    set(gca,'ylim',[0 1.1*mxy],'ytick',[])
    
    axes(handles.cdfaxes)
    hold on
    plot(v,BinomCDF(model,v),colour,'linewidth',handles.fitspecs.lw)
    axis tight
    drawnow

    % Add data re the fit to the figure
    set(handles.fitpdftext,'visible','on');
    set(handles.fitcdftext,'visible','on');
    
    % Keep the PDF info
    handles.fitspecs.v = v;
    handles.fitspecs.PDF = tmpPDF;
    

end

guidata(handles.figure1,handles);
