3-D histogram in spherical coordinates

4 次查看(过去 30 天)
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