From 208dd265044b2eabb168eb2e31630c0ea93bd28a Mon Sep 17 00:00:00 2001 From: Laura Nervo <laura.nervo@esrf.fr> Date: Wed, 18 Sep 2013 11:55:46 +0200 Subject: [PATCH] makeCornerHist : added inputs 'xtitle' 'ytitle' and output 'newFig' errorbar2 : added input 'color' cornerHist : added output 'f' and modified plot settings Signed-off-by: Laura Nervo <laura.nervo@esrf.fr> --- zUtil_Drawing/cornerHist.m | 23 ++++++++++--- zUtil_Drawing/errorbar2.m | 10 +++--- zUtil_Drawing/makeCornerHist.m | 60 ++++++++++++++++++++-------------- 3 files changed, 60 insertions(+), 33 deletions(-) diff --git a/zUtil_Drawing/cornerHist.m b/zUtil_Drawing/cornerHist.m index 71bed967..055a8aa1 100644 --- a/zUtil_Drawing/cornerHist.m +++ b/zUtil_Drawing/cornerHist.m @@ -1,5 +1,5 @@ -function [newScat, newHist] = cornerHist(scatPlot,histPlot,ratio) -%function [newScat, newHist] = cornerHist(scatPlot,histPlot,ratio) +function [f, newScat, newHist] = cornerHist(scatPlot,histPlot,ratio) +%function [f, newScat, newHist] = cornerHist(scatPlot,histPlot,ratio) % copies a scatter plot to a new figure, and puts a histogram corresponding to the scatter % plot in the top right corner. Ratio is optional to change the height of % the hist plot relative to its width - (ratio = width/height - ie. a ratio @@ -33,7 +33,7 @@ end f = figure; set(f,'position',[250 250 600 600]) scatAx = axes('Parent',f); -set(scatAx,'Position',[0.1 0.1 0.65 0.65]) +set(scatAx,'Position',[0.1 0.1 0.75 0.75]) % find length of bottom side of scatter plot lScat = get(scatAx,'position'); @@ -55,7 +55,7 @@ y = (LScat*limHist(end)/LimScat); % expand the plot until the corner hits the middle of this box. Therefor, % the size of our square is twice the length of y, so that the width of our % plot will be y times the square root of 2. -q = 2*y; +q = 1.3*y; % now if we do not have a square plot, we need to adjust the size of the % box so that the plot stays the right width q2 = (0.5*q) + (q/(2*ratio)); @@ -65,7 +65,7 @@ DAR(2) = DAR(2)*ratio; set(gca,'DataAspectRatio',DAR) figure(f) histAx = axes('Parent',f); -set(histAx,'Position',[.4 .4 q2 q2]) +set(histAx,'Position',[.7 .7 q2 q2]) % copy the scatter plot figure(scatPlot) @@ -85,10 +85,23 @@ newHist = copyobj(h,f); possub = get(histAx,'Position'); set(newHist,'XLim',newXlim) set(newHist,'YLim',newYlim) +set(newHist,'XTick',newXlim(1):25:newXlim(2)) +set(newHist,'YTick',newYlim(1):200:newYlim(2)) + set(newHist,'Position',... [possub(1) possub(2) possub(3) possub(4)]) delete(histAx) axes(newHist) box on +grid on +set(newHist,'GridLineStyle','--') +set(newHist,'XAxisLocation','top') +set(newHist,'YAxisLocation','left') +set(newHist,'LineWidth',1) +set(newHist,'FontSize',10) % rotate the hist plot camorbit(45, 0) + + +end + diff --git a/zUtil_Drawing/errorbar2.m b/zUtil_Drawing/errorbar2.m index c40f8ea2..0f2afa81 100644 --- a/zUtil_Drawing/errorbar2.m +++ b/zUtil_Drawing/errorbar2.m @@ -1,4 +1,4 @@ -function [hsym,hxe,hye] = errorbar2(x,y,xe,ye) +function [hsym,hxe,hye] = errorbar2(x,y,xe,ye,color) % plots a double errorbar plot. % [hsym,hxe,hye] = errorbar2(x,y,xe,ye) % Routine plots x+-xe vs. y+-ye @@ -31,11 +31,13 @@ qx = [x x repmat(nan,size(x))]'; qye = [y-ye y+ye repmat(nan,size(y))]'; qxe = [x-xe x+xe repmat(nan,size(x))]'; -hxe = plot(qxe(:),qy(:),'k-'); hold on; -hye = plot(qx(:),qye(:),'k-'); hold on; +hxe = plot(qxe(:),qy(:),'-'); hold on; +hye = plot(qx(:),qye(:),'--'); hold on; +set(hxe,'Color',color) +set(hye,'Color',color) % Plot the symbols last, so they are in front. -hsym = plot(x,y,'ko'); +hsym = plot(x,y,'k.'); set(hsym,'MarkerFaceColor','w'); hold off; diff --git a/zUtil_Drawing/makeCornerHist.m b/zUtil_Drawing/makeCornerHist.m index 19067354..8b87ef60 100644 --- a/zUtil_Drawing/makeCornerHist.m +++ b/zUtil_Drawing/makeCornerHist.m @@ -1,6 +1,6 @@ -function [newScat,newHist,bothBars,scatPoints] = makeCornerHist(x,y,xe,ye,nbins,xylimits,ratio,optHistc,addHist) -% [newScat,newHist,bothBars,scatPoints] = makeCornerHist(x,y,xe,ye,nbins,xylimits,ratio,optHistc,addHist) -% ------------------------------------------------------------------------------------------------------- +function [newFig, newScat,newHist,bothBars,scatPoints] = makeCornerHist(x,y,xe,ye,xtitle,ytitle,nbins,xylimits,ratio,optHistc,addHist) +% [newFig, newScat,newHist,bothBars,scatPoints] = makeCornerHist(x,y,xe,ye,xtitle,ytitle,nbins,xylimits,ratio,optHistc,addHist) +% --------------------------------------------------------------------------------------------------------------------- % % INPUT: % x = <double> vector of x values @@ -59,28 +59,29 @@ function [newScat,newHist,bothBars,scatPoints] = makeCornerHist(x,y,xe,ye,nbins, % % Version 001 07-03-2013 by LNervo -if nargin < 9 +if nargin < 11 addHist = []; end -if nargin < 8 +if nargin < 10 optHistc = []; end -if nargin < 7 - ratio = 2; +if nargin < 9 + ratio = 0.6; end -if nargin < 6 +if nargin < 8 xylimits = []; end -if nargin < 5 || isempty(nbins) +if nargin < 7 || isempty(nbins) nbins = 10; end if isempty(ratio) - ratio = 2; + ratio = 0.6; end scatFig = figure; hold on -[hsym,hxe,hye] = errorbar2(x,y,xe,ye); +barcolor = [0.501960784313725 0.501960784313725 0.501960784313725]; +[hsym,hxe,hye] = errorbar2(x,y,xe,ye,barcolor); pause(0.1) set(hsym,'Color', 'r', 'MarkerFaceColor','r') if isempty(xylimits) @@ -94,10 +95,12 @@ pause(0.1) set(gca,'Xlim',xylimits) set(gca,'Ylim',xylimits) axis square -set(gca,'TickDir','out','FontSize',14,'Box','off'); -line(get(gca,'XLim'), get(gca,'XLim'), 'Color', 'k'); -xlabel('w_B (bimodal schedule)'); -ylabel('w_B (unimodal schedule)'); +set(gca,'TickDir','in','FontSize',12,'Box','on'); +grid(gca,'on') +set(gca,'LineWidth',1) +hl = line(get(gca,'XLim'), get(gca,'XLim'), 'LineWidth',2,'Color',[0 0 1]); +xlabel(xtitle); +ylabel(ytitle); histFig = figure; d = x-y; @@ -116,23 +119,32 @@ else % end histPlot = bar(dd,nn,1); end -set(gca,'TickDir','out','FontSize',14,'Box','off'); -% let's make the histogram width 2/3 the width of the scatterplot, this -% should make a reasonably sized plot. -xlimit = 0.66 * (xylimits(2)-xylimits(1)); +set(gca,'TickDir','in','FontSize',12,'Box','on'); +set(histPlot,'FaceColor',[0.6 0.6 1]) +xlimit = max(round(max(abs(d))),50); xlim([-xlimit xlimit]); hold on %shading flat if ~isempty(addHist) - set(histPlot,'FaceColor',[1 1 1]) histPlot2 = bar(dd,NN,0.9); - set(histPlot2,'FaceColor',[0.6 0.6 0.6]) + set(histPlot2,'FaceColor',barcolor) set(histPlot2,'EdgeColor','none') -else - set(histPlot,'FaceColor',[0.6 0.6 0.6]) end -[newScat, newHist] = cornerHist(scatFig,histFig,ratio); +[~, newScat, newHist] = cornerHist(scatFig,histFig,ratio); bothBars = get(newHist,'Children'); scatPoints = get(newScat, 'Children'); +set(gcf,'Color',[1 1 1]) +set(gcf, 'Position', [200 200 800 800], 'Units', 'points') + +set(hsym,'DisplayName','Data') +set(hxe,'DisplayName','X Error Bar') +set(hye,'DisplayName','Y Error Bar') +set(hl,'DisplayName','Line y=x') + +leg=legend(newScat, [hxe,hye,hsym,hl]); +set(leg,'Position',[0.1633 0.8424 0.1747 0.1231]) +set(leg,'Units','normalized') + +newFig = gcf; end % end function -- GitLab