3-D histogram in spherical coordinates

조회 수: 6 (최근 30일)
Anitha S D
Anitha S D 2011년 5월 2일
I would like to plot a 3D histogram from data in spherical coordinate system. I have (theta, phi, h) each of which is of size 36* 9. Is there any way to plot 3D histogram in spherical coordinate system. My theta varies from 0 :2*pi:36 and phi varies from 0:pi/2:9. Using surf, I am getting it plotted as points only.

채택된 답변

Teja Muppirala
Teja Muppirala 2011년 5월 2일
Just for fun, and because it makes for a great example of visualizing spherical data,
here is a script to display a spherical coordinate histogram (here the histogram data is H):
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Set up the figure and data
colordef(figure,'black');
theta_vec = linspace(0,2*pi,36);
phi_vec = linspace(0,pi/2,9);
[theta,phi] = meshgrid(theta_vec,phi_vec);
% H is your histogram data
%H = 1+(theta.*(sin(phi))); %Another example
H = 100*(rand(size(phi)));
Hmax = max(H(:));
r = 0.03*Hmax; %Box size
polar(nan,max(max(H.*cos(phi))));
hold all;
%%Make the Histogram
for kk = 1:numel(theta_vec);
for jj = 1:numel(phi_vec);
X=r*([0 1 1 0 0 0;1 1 0 0 1 1;1 1 0 0 1 1;0 1 1 0 0 0]-0.5);
Y=r*([0 0 1 1 0 0;0 1 1 0 0 0;0 1 1 0 1 1;0 0 1 1 1 1]-0.5);
Z=[0 0 0 0 0 1;0 0 0 0 0 1;1 1 1 1 0 1;1 1 1 1 0 1]*H(jj,kk);
h= patch(X,Y,Z,0*X+H(jj,kk),'edgecolor','none');
rotate(h,[0 0 1],45,[0 0 0]);
rotate(h,[0 1 0],90 - 180/pi*phi_vec(jj),[0 0 0]);
rotate(h,[0 0 1],180/pi*theta_vec(kk),[0 0 0]);
end;
end;
%%Adjust the plot
[Xs,Ys,Zs] = sphere(size(theta,2)+1);
hs = surf(Hmax*Xs,Hmax*Ys,Hmax*Zs);
set(hs,'facecolor','none','edgecolor','w','edgealpha',0.2)
camlight;
set(gca,{'xtick' 'ytick' 'ztick' 'vis' 'clim'},{[] [] [] 'on' [0 Hmax]});
axis equal vis3d;
box on;
view(3);
colorbar
drawnow;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
There is some room for improvement here, but feel free to use/modify this if you'd like.

추가 답변 (1개)

Patrick Kalita
Patrick Kalita 2011년 5월 2일
Have you tried looking at bar3?
  댓글 수: 1
Anitha S D
Anitha S D 2011년 5월 3일
Thanks a lot Teja. It was of really great help. I tried with my histogram data and with slight modifications it started giving me expected results. Thanks once again for your valuable time spend on this.
Hi Patrick, I tried with bar3, but it will not give me is spherical coordinate system even if we convert in to cartesian and try. Thanks.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by