Search Comments and Ratings

go

   
Date File Comment by Comment Rating
06 Dec 2013 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

Yung-Yeh

Yung-Yeh

Very nice and decent code for displaying scatterplot in the 2D map with color for empirical distribution. The counting part was efficient only if you have a larger dataset but set a smaller # of bins. If you increase bin to larger than certain value it starts to get slowly even you have smaller dataset. I can't think of anything better but use an alternative approach for the condition with smaller dataset, and switch to the original method if the # of bin is actually smaller.

Following is my approach, similar to BLu's but with better decision switching between two methods. BTW, the centering bug was fixed in this version based on Thomas's post so length(C) == n

% do counts
if numel(x) < n^2
% New method
binIntX = diff(limitX)/(n-1);
binIntY = diff(limitX)/(n-1);
for idx = 1:numel(x)
idxX = min([round(x(idx)/binIntX)+1 numX]);
idxY = min([round(y(idx)/binIntY)+1 numY]);
C(idxY,idxX) = C(idxY,idxX) + 1;
end
else
% Old method
for i = 1:numY-1
for j = 1:numX-1
C(i,j) = length(find(x >= xEdges(j) & x < xEdges(j+1) &...
y >= yEdges(i) & y < yEdges(i+1)));
end
end
end

4
05 Jun 2013 LEGENDTITLE Add a title string inside a legend. Author: Steve Simon

Steve Simon

Peter

Peter

4
19 Nov 2012 LEGENDTITLE Add a title string inside a legend. Author: Steve Simon

Steve Simon

Felipe G. Nievinski

Felipe G. Nievinski

It seems the problem can be avoided calling the saveas function instead of clicking Save As from the figure window's File menu (which internally calls hgexport).

4
02 Jul 2012 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

Nic

Nic

5
21 Apr 2012 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

Julien

Julien

Very useful function.

5
02 Mar 2012 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

Thomas

Thomas

Centering bug:
I've symmetric data, but the cloud is not symmetric! Matt's solution does not solve the problem only by shifting the cloud. Debugging the code I found the C is non-symmetric padded by zeros and therefore not smoothed symmetric!

Solution:

C = zeros(numY-1,numX-1);

[...]

s = surf(linspace(minX,maxX,n),...
linspace(minY,maxY,n),...
zeros(numY-1,numX-1),C,...
'EdgeColor','none',...
'FaceColor','interp');

Comment only
23 Aug 2011 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

J G

J G

This would be really useful for scatter3 too, any suggestions how I could do that?

5
15 Jul 2011 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

J G

J G

Very cool function. Can it be done on a 3D scatter plot?

5
25 Apr 2011 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

BLu

BLu

It works well for small datasets and small n (such as 50).
I added a none option, as suggested above and changed the centering problem as suggested above.
I tried a large dataset and n=200, and have to terminate the calculation because it is taking too long. The code used in calculating the counts is not the most efficient. cloudPlot has a much more efficient algorithm. I made modification based on cloudPlot.

error(nargchk(2,6,nargin),'struct');

x = x(:);
y = y(:);

%new code
pointSelect = isinf(x) | isnan(x) | isinf(y) | isnan(y);
x = x(~pointSelect);
y = y(~pointSelect);
%new code ends

if length(x) ~= length(y)
error('SCATTERCLOUDDataVectorSizesDoNotMatch','The number of elements in x and y do not match')
end

if nargin < 6
%cmap = flipud(gray(256));
cmap='default';
end

if nargin < 5
%clm = 'k+';
clm='none';
end

if nargin < 4
l = 1;
end

if nargin < 3
n = 25;
end

% min/max of x and y
minX = min(x);
maxX = max(x);
minY = min(y);
maxY = max(y);

% edge locations
xEdges = linspace(minX,maxX,n);
yEdges = linspace(minY,maxY,n);

% shift edges
xDiff = xEdges(2) - xEdges(1);
yDiff = yEdges(2) - yEdges(1);
xEdges = [-Inf, xEdges(2:end) - xDiff/2, Inf];
yEdges = [-Inf, yEdges(2:end) - yDiff/2, Inf];

% number of edges
numX = numel(xEdges);
numY = numel(yEdges);

%new code
xBinIndex = floor((x - minX+xDiff/2)/xDiff)+1;
yBinIndex = floor((y - minY+yDiff/2)/yDiff)+1;
%new code ends

% hold counts
C = zeros(numY,numX);

% do counts
%new code
for i=1:numel(x)
C(yBinIndex(i),xBinIndex(i))=C(yBinIndex(i),xBinIndex(i))+1;
end
%new code ends

%for i = 1:numY-1
% for j = 1:numX-1
% C(i,j) = sum(x >= xEdges(j) & x < xEdges(j+1) &...
% y >= yEdges(i) & y < yEdges(i+1));
% end
% disp(num2str(i));
%end

% get rid of Infs from the edges
xEdges = [xEdges(2) - xDiff,xEdges(2:end-1), xEdges(end-1) + xDiff] + xDiff/2;
yEdges = [yEdges(2) - yDiff,yEdges(2:end-1), yEdges(end-1) + yDiff] + yDiff/2;

%xEdges = [xEdges(2) - xDiff,xEdges(2:end-1), xEdges(end-1) + xDiff];
%yEdges = [yEdges(2) - yDiff,yEdges(2:end-1), yEdges(end-1) + yDiff];

% smooth the density data, in both directions.
C = localSmooth(localSmooth(C,l)',l)';

% create the graphics
ax = newplot;
s = surf(xEdges,yEdges,zeros(numY,numX),C,...
'EdgeColor','none',...
'FaceColor','interp');
view(ax,2);
colormap(ax,cmap);
grid(ax,'off');
holdstate = get(ax,'NextPlot');
set(ax,'NextPlot','add');

if ~strcmpi(clm,'none')
p = plot(x,y,clm);
end

axis(ax,'tight');
set(ax,'NextPlot',holdstate)

% outputs
if nargout
h = [s;p];
end

function B = localSmooth(A,L)
r = size(A,1);
I = eye(r);
D1 = diff(I);
D2 = diff(I,2);
B = (I + L ^ 2 * D2' * D2 + 2 * L * D1' * D1) \ A;

3
27 Mar 2011 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

J G

J G

works great thanks!

5
01 Feb 2011 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

Matt Caywood

Matt Caywood

To fix the glaring centering bug, change these lines from:

xEdges = [xEdges(2) - xDiff,xEdges(2:end-1), xEdges(end-1) + xDiff];
yEdges = [yEdges(2) - yDiff,yEdges(2:end-1), yEdges(end-1) + yDiff];

TO:

xEdges = [xEdges(2) - xDiff,xEdges(2:end-1), xEdges(end-1) + xDiff] + xDiff/2;
yEdges = [yEdges(2) - yDiff,yEdges(2:end-1), yEdges(end-1) + yDiff] + yDiff/2;

In the future, if there's a "simple" fix, why not post it and be helpful?

4
26 Nov 2010 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

David Verrelli

David Verrelli

Hi, Ruello.
I haven't looked at this recently, but I believe that the point ended up being plotted at the 'bottom left' of each rectangular region over which the data points were summed.
—DIV

Comment only
08 Nov 2010 LEGENDTITLE Add a title string inside a legend. Author: Steve Simon

Steve Simon

Kaare

Kaare

saving it to jpg, png or pdf messes it up, haven't tried any other formats.

1
03 Nov 2010 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

Ruello Rubino

Ruello Rubino

David,
could you please elaborate on "Output is biased toward the origin" and what fix did you make?

PS: Ialso fixed clm='none' issue... but I am quite puzzled by the fact that I was sure it used to work... until yesterday!
This seems an issue in the built-in function plot :
>> plot(1:10,1:10,'none')
??? Error using ==> plot
Error in color/linetype argument
!!! 'none' is listed as a valid LineStyle property, or am I wrong?!?!?
In fact:
>> p=plot(1:10,1:10);
>> set(p,'LineStyle','none')
is OK... 0_0
Sorry if this is the wrong place to post...

Ruello

Comment only
17 Oct 2010 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

David Verrelli

David Verrelli

Output is biased toward the origin. A fix is fairly simple. It is also useful to be able to accept CLM = 'none'. I have made those two changes in my copy of the code.

4
02 Aug 2010 CITYPLOT Create 'cityplot' graphics. Author: Steve Simon

Steve Simon

B. Hiriyur

B. Hiriyur

5
28 Jul 2010 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

koji takahashi

koji takahashi

5
08 Dec 2009 LEGENDTITLE Add a title string inside a legend. Author: Steve Simon

Steve Simon

Cristian

Cristian

It does not work properly if you save the image as .eps.

2
24 Nov 2009 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

Pearl

Pearl

5
02 Oct 2009 LEGENDTITLE Add a title string inside a legend. Author: Steve Simon

Steve Simon

Ben Witvliet

Ben Witvliet

Just what I needed. Works fine in R2009a (64-bit version).

4
08 Sep 2009 LEGENDTITLE Add a title string inside a legend. Author: Steve Simon

Steve Simon

David DeVilbiss

David DeVilbiss

The function worked fine but will not allow the legend to be placed outside the axes.

3
02 Apr 2009 ClustalW Interface MATLAB tools for working with ClustalW. Author: Steve Simon

Steve Simon

Zeeshan

Zeeshan

Can anyone explain to me how to use this (not the GUI, the command line tool...through matlab)? Maybe someone can show me an example of how the call file is "called?"

Comment only
07 Jul 2008 LEGENDTITLE Add a title string inside a legend. Author: Steve Simon

Steve Simon

Thierry Dalon

With R2008a it works perfectly.
It puts the title inside the box legend in bold.
(Default title property of legend put a title outside of the legend box).

5
29 Jun 2008 ClustalW Interface MATLAB tools for working with ClustalW. Author: Steve Simon

Steve Simon

Pradosh Mahadani

as ussual

4
12 Apr 2008 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

Mark Tut

Thank you

5
31 Jan 2008 CBNEEDLE Add a 'needle' to a colorbar. Author: Steve Simon

Steve Simon

Jan Lauber

cool

4
27 Oct 2007 ClustalW Interface MATLAB tools for working with ClustalW. Author: Steve Simon

Steve Simon

Vivek Mutalik

Thanks. This is good.
Looking to get the positional nucleotide Matrix from multiple alignment result. This matrix would have: number of times different nucleotide appears at perticular position. This would help in analysing data using stat toolbox. If you can reply, that'll be great.

5
14 Jun 2007 LEGENDTITLE Add a title string inside a legend. Author: Steve Simon

Steve Simon

Romario Do Nacimento

The function doesn't work in Matlab 14!!
Another option please!

Comment only
21 Feb 2007 ClustalW Interface MATLAB tools for working with ClustalW. Author: Steve Simon

Steve Simon

re ma

coul you help me about HMM

Comment only
01 Jun 2006 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

Gotzon Basterretxea

5
20 Feb 2006 LEGENDTITLE Add a title string inside a legend. Author: Steve Simon

Steve Simon

valik pol

Didn't work: error in line 68: Function 'mrdivide' is not defined for values of class 'cell'.
I personally liked Jos' solution better, but this is supposed to put the title INSIDE the legend! And anyway, thanks for bringing up the issue! ;-)

2
22 Aug 2005 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

Kay Hamacher

Excatly what I needed. Thanks!

5
08 Jul 2005 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

Erik Benkler

very useful m-file.

5
06 May 2005 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon

Steve Simon

paul naude

Just what I was looking for! Now, how can one change the shade to a cold-hot colour?

4
04 May 2005 ClustalW Interface MATLAB tools for working with ClustalW. Author: Steve Simon

Steve Simon

shailendra asthana

nice software

Comment only
29 Apr 2005 LEGENDTITLE Add a title string inside a legend. Author: Steve Simon

Steve Simon

Michel Garcia

didn't work!

Comment only
25 Mar 2005 SCATTERSHAPE Turn patches from SCATTER into shapes. Author: Steve Simon

Steve Simon

hafedh gaha

The example doesn't function

scattershape(h,starx,stary,gray(length(h)))
??? Error using ==> scattershape
First input must be an array of handles.

Comment only
07 Oct 2004 LEGENDTITLE Add a title string inside a legend. Author: Steve Simon

Steve Simon

Holger Krause

Unfortunately this nice function doesn't work with R14.

Comment only
16 Sep 2004 ClustalW Interface MATLAB tools for working with ClustalW. Author: Steve Simon

Steve Simon

pravin paul

thanks

Comment only
14 Aug 2004 ClustalW Interface MATLAB tools for working with ClustalW. Author: Steve Simon

Steve Simon

nirmal barathi

4
16 Jun 2004 LEGENDTITLE Add a title string inside a legend. Author: Steve Simon

Steve Simon

Chris Rodgers

Although this looks nice when first applied to a plot, it gets messed up as soon as I resize the plot... :-( This is more important than it might initially seem, since I use the exportfig.m tools to export / print my figures and this always involves a resize.

3
01 Jun 2004 LEGENDTITLE Add a title string inside a legend. Author: Steve Simon

Steve Simon

Andreas Hartmann

Nice function, and not redundant, it adds the title _inside_ the legend box

5
05 Mar 2004 LEGENDTITLE Add a title string inside a legend. Author: Steve Simon

Steve Simon

Jos x

Redundant! This does the job already:
>> h = legend(...) ;
>> set(get(h,'title'),'String','Legend Title')

1
04 Mar 2004 LEGENDTITLE Add a title string inside a legend. Author: Steve Simon

Steve Simon

Fahad Al Mahmood

Excellent function! Very easy to use ... thank you!

5
29 Dec 2003 ClustalW Interface MATLAB tools for working with ClustalW. Author: Steve Simon

Steve Simon

Wriddhiman Ghosh

Real friend of molecular microbiologists.
Most user friendly.

5

Contact us