Code covered by the BSD License  

Highlights from
Create a colored, tilted 2D error ellipse scatter plot.

Create a colored, tilted 2D error ellipse scatter plot.

by

 

Create a colored, tilted 2D error ellipse scatter plot.

errorellipse(ex,ey,xx,yy,varargin)
function hh = errorellipse(ex,ey,xx,yy,varargin)
%errorellipse(ex,ey,xx,yy,varargin) creates a colored ellipses
%   This creates tilted ellipses at each centroid position and then shades
%   them based on some weight.
%% condition the input
hh = zeros(size(xx));
th = zeros(size(xx));
cmaps = ones(size(xx))*[.5,.5,.5];
if nargin == 5
    th = varargin{1};
elseif nargin == 6
    th = varargin{1};
    cmaps = varargin{2};
elseif nargin == 7
    th = varargin{1};
    wts = varargin{2};
    mapstr = varargin{3};
    cm = flipud(colormap(mapstr));
    cm_o = linspace(min(wts),max(wts),size(cm,1))';
    cmaps(:,1) = interp1(cm_o,cm(:,1),wts,'linear');
    cmaps(:,2) = interp1(cm_o,cm(:,2),wts,'linear');
    cmaps(:,3) = interp1(cm_o,cm(:,3),wts,'linear');
end
%% add them to an open plot
hold on
t = linspace(0,2*pi);
for ii = 1:numel(xx)
    x = xx(ii) + ex(ii).*cos(t).*cosd(th(ii)) - ey(ii).*sin(t).*sind(th(ii));
    y = yy(ii) + ex(ii).*cos(t).*sind(th(ii)) + ey(ii).*sin(t).*cosd(th(ii));
    hh(ii,1) = patch(x,y,'k','line','none');
    set(hh(ii,1),'facecolor',cmaps(ii,:))
    clear x y
end
end

Contact us