本帖最后由 meatball1982 于 2017-3-28 13:52 编辑
别人的问题
http://www.ilovematlab.cn/forum. ... 1&extra=#pid3168135
最近觉得一个3D图从不同的角度看,效果相当的好。
帖子中只是要画出环的部分,将原曲面通过透明的方式显示。似乎效果更加的好。
- clear all
- clc
- clf
- r=linspace(1,1.5,50);
- the=linspace(0,2*pi,200);
- the=[the,0];
- [R,The]=meshgrid(r,the);
- x=R.*cos(The);
- y=R.*sin(The);
- X=x+2;
- Y=y+2;
- Z=X.*Y;
- x_g=linspace(0.5,3.5,100);
- y_g = linspace(0.5,3.5,100);
- [X_g,Y_g]=meshgrid(x_g,y_g);
- Z_g =X_g.*Y_g;
- sbp_width=0.75;
- sbp_heig=0.75;
- n_row = 2;
- n_col = 2;
- [out_pos]=fun_mm_subplot_pos(n_row,n_col,sbp_width,sbp_heig);
- h=figure(1)
- set(h, 'Position', [100, 100, 400, 400]);
- ax=axes('position',out_pos(1,:));
- hold on
- h=surf(X_g,Y_g,Z_g,'edgecolor','none')
- alpha(h,0.2)
- surf(X,Y,Z,Z,'edgecolor','none')
- colormap(jet)
- % colormap(h2,cool)
- view(-20,20)
- axis tight
- grid on
- ax=axes('position',out_pos(2,:));
- hold on
- h=surf(X_g,Y_g,Z_g,'edgecolor','none')
- alpha(h,0.2)
- surf(X,Y,Z,Z,'edgecolor','none')
- colormap(jet)
- axis equal tight
- view(0,90)
- ax=axes('position',out_pos(3,:));
- hold on
- h=surf(X_g,Y_g,Z_g,'edgecolor','none')
- alpha(h,0.2)
- hsurf(X,Y,Z,Z,'edgecolor','none')
- colormap(jet)
- axis tight
- view(0,0)
- grid on
- ax=axes('position',out_pos(4,:));
- hold on
- h=surf(X_g,Y_g,Z_g,'edgecolor','none')
- alpha(h,0.2)
- surf(X,Y,Z,Z,'edgecolor','none')
- colormap(jet)
- axis tight
- view(-90,0)
- grid on
复制代码
其中的
可以用subplot函数来代替,不过我觉得我的更加好些。
- function [out_pos]=fun_mm_subplot_pos(n_row,n_col,sbp_width,sbp_heig);
- % subplot pos
- % input : -----------------
- % n_row : number of row
- % n_col : number of column
- % sbp_width : subplot width 0-1
- % sbp_heig : subplot height 0-1
- % output : ----------------
- % out_pos
- %
- %
- % sbp_width=0.8;
- % sbp_heig=0.85;
- % n_row = 4;
- % n_col = 6;
- % [out_pos]=fun_mm_subplot_pos(n_row,n_col,sbp_width,sbp_heig);
- % h=figure(1)
- % set(h, 'Position', [100, 100, 800, 600]);
- % [x,y,z]=peaks(30);
- % caxis_mm=[-5 30];
- % for i=1:n_row*n_col
- % ax=axes('position',out_pos(i,:));
- % surf(x,y,z+i,'edgecolor','none')
- % caxis(caxis_mm)
- % view(0,90)
- % hold on
- % text([2],[2],[30],mat2str(i),'fontsize',20)
- % end
- for i=1:n_row*n_col
- k1=ceil(i/n_col);
- k2=i-(k1-1)*n_col;
-
- out_pos(i,:)=[(1-sbp_width)/n_col/2 + (k2-1)/n_col,...
- (1-sbp_heig )/n_row/2 + (n_row-k1)/n_row, ...
- sbp_width/n_col,...
- sbp_heig/n_row];
- end
复制代码
|