meatball1982 发表于 2019-9-25 15:52:48

豆粑粑 matlab 极坐标下的散点分页

本帖最后由 meatball1982 于 2019-9-25 15:58 编辑

在极坐标下,把两组散点用等高线的方式表达出来。
因为散点基本在一起,分不清具体的方向。

图1 是两组数的极点坐标下的位置。
图2 是连线的版本。
图3 是出现次数的统计(平滑后的)。两个不同的colormap代表了不同的数据的分页,散点根据colormap的最低color着色。

这时的统计和帖子
https://www.ilovematlab.cn/thread-539582-1-1.html
思路一致。
数据和程序在附件中。









主程序:
clear all
clc
close all


dat = load('../file_data/dat.txt');

%
R=dat(:,1);
% Rmax = max(R);
R1=R;
R2=R;
the1 = dat(:,2)*pi/180;
the2 = dat(:,3)*pi/180;



h=figure(1)
set(h, 'Position', );
h1 = polar(the1,R1);
set(h1,'color','b','linewidth',0.5)
hold on
h2=polar(the2,R2);
set(h2,'color','r','linewidth',0.5)


h=figure(2)
set(h, 'Position', );
h1 = polar(the1,R1,'o');
set(h1,'markersize',0.8,'markerfacecolor','b','markeredgecolor','none')
hold on
h2=polar(the2,R2,'o');
set(h2,'markersize',0.8,'markerfacecolor','r','markeredgecolor','none')



figure(3)
pl_lev =;
=fun_polar_2group(R1,the1,R2,the2,pl_lev)





画图函数:
function =fun_polar_2group(R1,the1,R2,the2,pl_lev)
% =fun_polar_2group(R1,the1,R2,the2,pl_lev)
% inputs
% R1:   rad of 1st group data
% the1:   theta of 1st group data
% R2:   rad of 2nd group data
% the2:   theta of 2nd group data
% pl_lev : the contour line value of plot each group
% outputs
% h:      handle of the figure
% first typed by mm
% contact me : meatball1982@163.com

%% main
% cart cor
x1 = R1.*cos(the1);
y1 = R1.*sin(the1);
x2 = R2.*cos(the2);
y2 = R2.*sin(the2);



Rmax = max(max(R1),max(R2));

% grid number
n_x = 200;
n_y = 199;

x_lin = linspace(-1.1*Rmax,1.1*Rmax,n_x);
y_lin = linspace(-1.1*Rmax,1.1*Rmax,n_y);

=meshgrid(x_lin,y_lin);
Z1_mat =zeros(size(X_mat));
Z2_mat =zeros(size(X_mat));


% static numb in each grid
for i = 1:(n_x-1)
    for j = 1:(n_y-1)
      ind = x1 > x_lin(i) & x1<=x_lin(i+1) & ...
            y1 > y_lin(j) & y1<=y_lin(j+1);
          Z1_mat(j,i)=sum(ind);
    end
end


for i = 1:(n_x-1)
    for j = 1:(n_y-1)
      ind = x2 > x_lin(i) & x2<=x_lin(i+1) & ...
            y2 > y_lin(j) & y2<=y_lin(j+1);
          Z2_mat(j,i)=sum(ind);
    end
end

% smooth the data, change 9 if necessary.
Z1_mat_sm = smooth2(Z1_mat,9,9);
Z2_mat_sm = smooth2(Z2_mat,9,9);

% colormap
tm = jet(120);
col_h1 = flipud(tm(10:50,:));
tm = hot(100);
col_h2 = flipud(tm(20:70,:));


% plot data 1
ax1 = axes;
axis off
axis equal
hidden off
h1 = polar(ax1,the1,R1,'o');
set(h1,'markersize',1,'markeredgecolor','none','markerfacecolor',col_h1(1,:));
hold on
[~,hContour1]=contour(ax1,X_mat,Y_mat,Z1_mat_sm,pl_lev,'linewidth',2);

% plot data 2
ax2= axes;
hold on
plot(x2,y2,'o','markeredgecolor','none','markerfacecolor',col_h2(1,:),'markersize',1);
axis off
axis equal
hidden off
[~,hContour2]=contour(ax2,X_mat,Y_mat,Z2_mat_sm,pl_lev,'linewidth',2);

% link two axes
linkaxes();
ax2.Visible = 'off';
ax2.XTick=[];
ax2.YTick =[];

colormap(ax1,col_h1);
colormap(ax2,col_h2);

% plot position
set(,'Position',,'fontsize',12);
cb1 = colorbar(ax1,'Position',[.75 .11 .0675 .815],'fontsize',12);
cb2 = colorbar(ax2,'Position',[.88 .11 .0675 .815],'fontsize',12);
axis([-1.2* Rmax 1.2* Rmax -1.2 * Rmax 1.2* Rmax])

% output
h=gcf;



页: [1]
查看完整版本: 豆粑粑 matlab 极坐标下的散点分页