% powerlaw plotting 
%jianguo lu, Sept 2010.

n=500;
alpha=2;
xmin=1;
%generate n random numbers following power law
    rawData = xmin*(1-rand(n,1)).^(-1/(alpha-1));

%rawData=randht(2000, 'powerlaw',1.5);
rawData
subplot(3,2,1);
scatter(1:n, rawData);
title('(A) Scatter plot of 500 random data');

rawData
subplot(3,2,2);
scatter(1:n, rawData, rawData.^(0.5),rawData);
title('(B) Crowded dots are plooted in smaller size');

b=5;
bins=1:b:n;
h=hist(rawData, bins);
subplot(3,2,3);
plot(h, 'o');
xlabel('value');
ylabel('frequency');
title('(C) Histogram of equal bin size');

subplot(3,2,4);
plot(log10(bins), log10(h), 'o');
xlabel('value');
ylabel('frequency');

title('(D) log-log plot of C');

binslog(1)=1;
for j=1:7
    b2(j)=2^j
    binslog(j+1)=binslog(j)+b2(j);
end;
bins
subplot(3,2,5);
h=hist(rawData, binslog);
plot(binslog, h, 'o');
xlabel('value');
ylabel('frequency');
title('(E)Histogram of log bin size');


subplot(3,2,6);
h=hist(rawData, binslog);
plot(log10(binslog), log10(h), 'o');
xlabel('value');
ylabel('frequency');
title('(F) log-log plot of (E)');

