Skip to content
Snippets Groups Projects
Commit 208dd265 authored by Laura Nervo's avatar Laura Nervo
Browse files

makeCornerHist : added inputs 'xtitle' 'ytitle' and output 'newFig'

errorbar2 : added input 'color'
cornerHist : added output 'f' and modified plot settings

Signed-off-by: default avatarLaura Nervo <laura.nervo@esrf.fr>
parent 4ca9e8e1
No related branches found
No related tags found
No related merge requests found
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
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;
......
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment