Created
June 8, 2015 08:16
-
-
Save karthikraman/311e1c1b5fc00be3385a to your computer and use it in GitHub Desktop.
BubblePlot for MATLAB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function h=bubbleplot(varargin) | |
%BUBBLEPLOT Bubble plot, using MATLAB's scatter | |
% | |
% x, y -- data | |
% | |
x=varargin{1}(:); | |
y=varargin{2}(:); | |
data=sortrows([x y]); | |
unq_data=unique(data,'rows'); | |
nPoints=size(x,1); | |
chk=isnan(unq_data); | |
[i,j]=find(chk); | |
if(~isempty(i)) | |
warning('NaNs found in data!'); | |
unq_data(i,:)=[]; | |
nPoints=nPoints-length(i); | |
end | |
s=zeros(size(unq_data,1),1); | |
for k=1:length(s) | |
s(k)=sum(sum(bsxfun(@eq,data,unq_data(k,:)),2)==2); | |
end | |
if(sum(s)~=nPoints) | |
warning('Something not right. Data points not tallying!\n'); | |
end | |
if(max(s)>50) | |
scale=2000/max(s); | |
else | |
scale=36; | |
end | |
h=scatter(unq_data(:,1),unq_data(:,2),s*scale,varargin{3:end}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment