www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@xregmultigraph2d/private/pr_plot.m
function pr_plot(gr) %PR_PLOT Perform plotting in the object % % PR_PLOT(GR) is a private method which performs the plotting in GR % Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc. xfac=get(gr.xfactor,'Value'); yfac=get(gr.yfactor,'Value'); labels=get(gr.xfactor,'String'); ud = get(gr.axes,'UserData'); switch lower(ud.type) case 'single' data = get(gr.xtext,'UserData'); if isempty(data) xdata=[]; ydata=[]; else xdata=data(:,xfac); ydata=data(:,yfac); end if ud.colorbar && ud.colorbarvalid if ud.colordatavalid && get(gr.colorbar,'currentfactor')==1 i_PEColorPlot(gr,ud.lines,ud.patches,ud.excludestyle,ud.checkedfillmask,xdata,ydata); else i_MultiColorPlot(gr,ud.lines,ud.patches,ud.excludestyle,ud.checkedfillmask,xdata,ydata); end else i_PlainPlot(gr,ud.lines,ud.patches,ud.checkedmcolor{1},ud.checkedfillmask,xdata,ydata) end str=[labels(xfac);labels(yfac)]; no_lines = 1; title=[labels{yfac} ' v ' labels{xfac}]; if isempty(ud.title) set(get(gr.axes,'Title'),'String',title,'Interpreter','none'); end case {'multi','multinoerror'} ylabels=get(gr.yfactor,'String'); str=[labels(xfac);ylabels(yfac)]; xdata = get(gr.xtext,'UserData'); plotxy = 0; if length(ud.checkedyfactors)<=3 title = []; for i = 1:length(ud.checkedyfactors) title = [title ud.checkedyfactors{i} ', ']; end title = title(1:end-2); else title = 'Selected items'; end title = [title ' v ' labels{xfac}]; if ud.xypossible % 2 items plotted - May be error or x-y selection switch yfac case 1 % Normal selection xdata = xdata(:,xfac-1); fill = ud.checkedfillmask(:,xfac-1); ydata = get(gr.ytext,'UserData'); case 2 % X-Y Selection data = get(gr.ytext,'UserData'); xdata = data(:,1); ydata = data(:,2); fill = 1; plotxy = 1; title = [ud.checkedyfactors{2} ' v ' ud.checkedyfactors{1}]; str = ud.checkedyfactors(:); otherwise xdata = xdata(:,xfac-1); ydata = get(gr.ytext,'UserData'); fill = 1; % plot filled err = ydata(:,1) - ydata(:,2); relerr = err./(ydata(:,2) + eps).*100; switch yfac case 3 ydata = err; case 4 ydata = abs(err); case 5 ydata = relerr; case 6 ydata = abs(relerr); end title = [ylabels{yfac} ' (' ud.checkedyfactors{1} ' - ' ... ud.checkedyfactors{2} ') v ' labels{xfac}]; end else % just plot selection if ~isempty(xdata) xdata = xdata(:,xfac); fill = ud.checkedfillmask(:,xfac); else fill = []; end ydata = get(gr.ytext,'UserData'); end % this was the y=x line which is now obsolete set(ud.lines(end),'XData',[],'YData',[]); if ud.colorbar && ud.colorbarvalid if ud.colordatavalid && get(gr.colorbar,'currentfactor')==1 i_PEColorPlot(gr,ud.lines,ud.patches,ud.excludestyle,fill,xdata,ydata); else i_MultiColorPlot(gr,ud.lines,ud.patches,ud.excludestyle,fill,xdata,ydata); end else i_SingleColorPlot(gr,ud.lines,ud.patches,ud.checkedmcolor,fill,xdata,ydata); end no_lines = size(ydata,2); if isempty(ud.title) set(get(gr.axes,'Title'),'String',title,'Interpreter','none'); end case 'table' index = ud.tableindex; col = [0 0 1]; data = get(gr.xtext,'UserData'); if isempty(data) xdata=[]; ydata=[]; fill = 1; index = []; else xdata = data(:,xfac); ydata = data(:,yfac); fill = 1; end % Plot the valid points (colored or plain) if ud.colorbar && ud.colorbarvalid i_MultiColorPlot(gr,ud.lines,ud.patches,'table',fill,xdata,ydata,index); else i_PlainPlot(gr,ud.lines,ud.patches,col,fill,xdata,ydata,index); end str=[labels(xfac);labels(yfac)]; str = i_TablePlot(gr,ud.lines,xdata,ydata,index,str); no_lines = 1; end if ud.grid grid='on'; else grid='off'; end set(gr.axes,'XGrid',grid,'YGrid',grid); lbls=get(gr.axes,{'XLabel','YLabel'}); set([lbls{:}],{'String'},str,'Interpreter','none'); calltype = max(1,min(2,no_lines)); if calltype~=ud.lastcalltype ud.lastcalltype = calltype; set(gr.axes,'UserData',ud); if calltype==1 xregcallback(ud.singlecallback); elseif calltype~=1 xregcallback(ud.multicallback); end end %----------------------------------------------------------------------- function i_PlainPlot(gr,lines,patches,color,fill,xdata,ydata,index) %----------------------------------------------------------------------- if nargin<8 index = 1:size(xdata,1); end if fill set(lines(1),'XData',xdata(index),'YData',ydata(index),... 'MarkerFaceColor',color,'MarkerEdgeColor','none'); else set(lines(1),'XData',xdata(index),'YData',ydata(index),... 'MarkerEdgeColor',color,'MarkerFaceColor','none'); end set(lines(2:end),'XData',[],'YData',[]); set(patches,'Faces',[]); %----------------------------------------------------------------------- function i_SingleColorPlot(gr,lines,patches,color,fill,xdata,ydata) %----------------------------------------------------------------------- % Single color plot for i = 1:size(ydata,2) if fill(i) set(lines(i),'XData',xdata,'YData',ydata(:,i),... 'MarkerEdgeColor','none','MarkerFaceColor',color{i}); else set(lines(i),'XData',xdata,'YData',ydata(:,i),... 'MarkerFaceColor','none','MarkerEdgeColor',color{i}); end end set(patches,'Faces',[]); % Turn other lines off (may be plotting error) set(lines(i+1:end-1),'XData',[],'YData',[]); %----------------------------------------------------------------------- function i_MultiColorPlot(gr,lines,patches,style,fill,xdata,ydata,index) %----------------------------------------------------------------------- if nargin<8 index = get(gr.colorbar,'index'); end notindex = []; switch style case 'color' [unused, bin]=histc(get(gr.colorbar,'CData'),get(gr.colorbar,'edges')); bin(bin==0)=1; cmap = get(gr.colorbar,'cmap'); coldata=cmap(bin(:),:); index = 1:size(ydata,1); case 'exclude' coldata = get(gr.colorbar,'colordata'); case 'blank' coldata = get(gr.colorbar,'colordata'); notindex = setdiff(1:size(ydata,1),index); case 'table' if isempty(index) coldata = []; else cdata = get(gr.colorbar,'CData'); [unused, bin]=histc(cdata(index),get(gr.colorbar,'edges')); bin(bin==0)=1; cmap = get(gr.colorbar,'cmap'); coldata=cmap(bin(:),:); end end for i = 1:size(ydata,2) if fill(i) set(patches(i),'XData',xdata(index),'YData',ydata(index,i),... 'MarkerEdgeColor','none','MarkerFaceColor','flat',... 'FaceVertexCData',coldata); else set(patches(i),'XData',xdata(index),'YData',ydata(index,i),... 'MarkerFaceColor','none','MarkerEdgeColor','flat',... 'FaceVertexCData',coldata); end set(lines(i),'XData',xdata(notindex),'YData',ydata(notindex,i),... 'MarkerFaceColor','none','MarkerEdgeColor','k'); end % Turn other lines off (may be plotting error) set(lines(i+1:end-1),'XData',[],'YData',[]); set(patches(i+1:end),'Faces',[]); %----------------------------------------------------------------------- function i_PEColorPlot(gr,lines,patches,style,fill,xdata,ydata) %----------------------------------------------------------------------- cdata = get(gr.yfactor,'UserData'); for i = 1:size(ydata,2) coldata = cdata(:,i); notindex = []; cmax = get(gr.colorbar,'cmax'); cmin = get(gr.colorbar,'cmin'); switch style case 'color' index = 1:size(ydata,1); case 'exclude' index = find(coldata<=cmax & coldata>=cmin); case 'blank' index = find(coldata<=cmax & coldata>=cmin); notindex = setdiff(1:size(ydata,1),index); end f = find(isnan(coldata)); index = setdiff(index,f); notindex = union(notindex,f); coldata = coldata(index); edges = get(gr.colorbar,'edges'); cmap = get(gr.colorbar,'cmap'); if ~isempty(coldata) && ~isempty(edges) [unused, bin]=histc(coldata,edges); bin(bin==0)=1; coldata=cmap(bin(:),:); if fill(i) set(patches(i),'XData',xdata(index),'YData',ydata(index,i),... 'MarkerEdgeColor','none','MarkerFaceColor','flat',... 'FaceVertexCData',coldata); else set(patches(i),'XData',xdata(index),'YData',ydata(index,i),... 'MarkerFaceColor','none','MarkerEdgeColor','flat',... 'FaceVertexCData',coldata); end else set(patches(i),'Faces',[]); end set(lines(i),'XData',xdata(notindex),'YData',ydata(notindex,i),... 'MarkerFaceColor','none','MarkerEdgeColor','k'); end % Turn other lines off (may be plotting error) set(lines(i+1:end-1),'XData',[],'YData',[]); set(patches(i+1:end),'Faces',[]); %----------------------------------------------------------------------- function str = i_TablePlot(gr,lines,xdata,ydata,index,str) %----------------------------------------------------------------------- notindex = setdiff(1:size(ydata,1),index); set(lines(2),'XData',xdata(notindex),'YData',ydata(notindex,:),... 'MarkerFaceColor','none','MarkerEdgeColor','k'); % Get some table info tud = get(gr.xfactor,'UserData'); xfac=get(gr.xfactor,'Value'); yfac=get(gr.yfactor,'Value'); dfac = length(get(gr.xfactor,'String')); xaxis = 0; yaxis = 0; daxis = 0; if isempty(tud) ptrs = []; else ptrs = tud.axesptrs; end switch length(ptrs) case 2 % Do axes names match up with current graph? if length(tud.xfactor_i(1))==1 && length(tud.xfactor_i(2))==1 if tud.xfactor_i(1)==xfac xaxis = 1; elseif tud.xfactor_i(1)==yfac yaxis = 1; end if tud.xfactor_i(2)==xfac xaxis = 2; elseif tud.xfactor_i(2)==yfac yaxis = 2; end if xfac==dfac daxis = 1; elseif yfac == dfac daxis = 2; end end case 1 % 1D table if length(tud.xfactor_i(1))==1 if tud.xfactor_i(1)==xfac xaxis = 1; elseif tud.xfactor_i(1)==yfac yaxis = 1; end if xfac==dfac daxis = 1; elseif yfac == dfac daxis = 2; end end end if xaxis str{1} = [str{1} ' (table axis)']; if size(tud.axes{xaxis}, 1) > 1 tud.axes{xaxis} = tud.axes{xaxis}'; end set(gr.axes,'XTick',tud.axes{xaxis},... 'XTickLabel', pr_genaxisticklabels(tud.axes{xaxis}, 4)); else set(gr.axes,'XTickMode','auto','XTickLabelMode','auto'); end if yaxis str{2} = [str{2} ' (table axis)']; if size(tud.axes{yaxis}, 1) > 1 tud.axes{yaxis} = tud.axes{yaxis}'; end set(gr.axes,'YTick',tud.axes{yaxis},... 'YTickLabel',pr_genaxisticklabels(tud.axes{yaxis}, 4)); else set(gr.axes,'YTickMode','auto','YTickLabelMode','auto'); end if xaxis || yaxis locks = tud.locks; % match xdata, ydata if xaxis==1, locks = locks'; end locks = locks(:); lockindex = find(locks); notindex = find(~locks); end if xaxis && yaxis xdata = repmat(tud.axes{xaxis}(:),length(tud.axes{yaxis}),1); ydata = repmat(tud.axes{yaxis}(:)',length(tud.axes{xaxis}),1); ydata = ydata(:); set(lines(3),'XData',xdata(lockindex),'YData',ydata(lockindex),... 'Marker','x',... 'MarkerFaceColor','r','MarkerEdgeColor','r'); set(lines(4),'XData',xdata(notindex),'YData',ydata(notindex),... 'Marker','x',... 'MarkerFaceColor','none','MarkerEdgeColor',[0.2 0.2 0.2]); elseif daxis && (xaxis || yaxis) vals = tud.values; if xaxis==1, vals = vals'; end vals = vals(:); if daxis==1 ydata = repmat(tud.axes{yaxis}(:)',length(tud.axes{3-yaxis}),1); xdata = vals; else xdata = repmat(tud.axes{xaxis}(:),length(tud.axes{3-xaxis}),1); ydata = vals; end set(lines(3),'XData',xdata(lockindex),'YData',ydata(lockindex),... 'Marker','x',... 'MarkerFaceColor','r','MarkerEdgeColor','r'); set(lines(4),'XData',xdata(notindex),'YData',ydata(notindex),... 'Marker','x',... 'MarkerFaceColor','none','MarkerEdgeColor',[0.2 0.2 0.2]); end