Created
June 9, 2013 05:23
-
-
Save asw456/5737748 to your computer and use it in GitHub Desktop.
3D histogram colored by z-value in Matlab
This file contains 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
%a = kelly(:) | |
%b = repmat([1:1:14]',8,1) | |
%c = kron([1:1:8],ones(1,14))' | |
%d = [ b, c] | |
%hist3(a,{ b c }) | |
kelly1 = kelly'; | |
close all | |
figure() | |
%axes('xlim',[0 15],'ylim',[0 9],'zlim',[0 30],'dataaspectratio',[1 1 5],'plotboxaspectratio',[1 1 1],'xtick',[],'ytick',[],'ztick',[]) | |
axes('xlim',[0 15],'ylim',[0 9],'zlim',[0 50],'projection','perspective','dataaspectratio',[1 1 5],'plotboxaspectratio',[1 1 1],'xtick',[],'ytick',[],'ztick',[]) | |
hold on | |
box on | |
%bh=bar3((kelly1 - ones(size(kelly1))*min(kelly1(:)))); | |
bh=bar3((kelly1)); | |
view(113,25) | |
for i=1:length(bh) | |
set(bh(i),'cdata',... | |
get(bh(i),'zdata')); | |
end | |
colormap(jet); | |
colorbar; | |
figure() | |
surf(1:8,1:14,kelly) | |
figure() | |
mesh(kelly) | |
figure() | |
[u,v] = meshgrid(1:8,1:14) | |
% Generate some normally distributed data | |
x = randn(50,1); | |
y = randn(50,1); | |
% Estimate a continuous pdf from the discrete data | |
[pdfx xi]= ksdensity(x); | |
[pdfy yi]= ksdensity(y); | |
% Create 2-d grid of coordinates and function values, suitable for 3-d plotting | |
[xxi,yyi] = meshgrid(xi,yi); | |
[pdfxx,pdfyy] = meshgrid(pdfx,pdfy); | |
% Calculate combined pdf, under assumption of independence | |
pdfxy = pdfxx.*pdfyy; | |
% Plot the results | |
mesh(xxi,yyi,pdfxy) | |
set(gca,'XLim',[min(xi) max(xi)]) | |
set(gca,'YLim',[min(yi) max(yi)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment