Mathematica中文论坛-非官方

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 13440|回复: 0
打印 上一主题 下一主题

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

[复制链接]

532

主题

602

帖子

3027

积分

论坛元老

Rank: 8Rank: 8

积分
3027
跳转到指定楼层
楼主
发表于 2019-9-25 15:52:48 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 meatball1982 于 2019-9-25 15:58 编辑

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

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

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









主程序:
  1. clear all
  2. clc
  3. close all


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

  5. %
  6. R=dat(:,1);
  7. % Rmax = max(R);
  8. R1=R;
  9. R2=R;
  10. the1 = dat(:,2)*pi/180;
  11. the2 = dat(:,3)*pi/180;



  12. h=figure(1)
  13. set(h, 'Position', [1000, 100, 400, 400]);
  14. h1 = polar(the1,R1);
  15. set(h1,'color','b','linewidth',0.5)
  16. hold on
  17. h2=polar(the2,R2);
  18. set(h2,'color','r','linewidth',0.5)


  19. h=figure(2)
  20. set(h, 'Position', [1000, 100, 400, 400]);
  21. h1 = polar(the1,R1,'o');
  22. set(h1,'markersize',0.8,'markerfacecolor','b','markeredgecolor','none')
  23. hold on
  24. h2=polar(the2,R2,'o');
  25. set(h2,'markersize',0.8,'markerfacecolor','r','markeredgecolor','none')



  26. figure(3)
  27. pl_lev =[0.07 0.4 0.7];
  28. [h]=fun_polar_2group(R1,the1,R2,the2,pl_lev)



复制代码


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

  13. %% main
  14. % cart cor
  15. x1 = R1.*cos(the1);
  16. y1 = R1.*sin(the1);
  17. x2 = R2.*cos(the2);
  18. y2 = R2.*sin(the2);



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

  20. % grid number
  21. n_x = 200;
  22. n_y = 199;

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

  25. [X_mat,Y_mat]=meshgrid(x_lin,y_lin);
  26. Z1_mat =zeros(size(X_mat));
  27. Z2_mat =zeros(size(X_mat));


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


  36. for i = 1:(n_x-1)
  37.     for j = 1:(n_y-1)
  38.         ind = x2 > x_lin(i) & x2<=x_lin(i+1) & ...
  39.               y2 > y_lin(j) & y2<=y_lin(j+1);
  40.           Z2_mat(j,i)=sum(ind);
  41.     end
  42. end

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

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


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

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

  68. % link two axes
  69. linkaxes([ax1,ax2]);
  70. ax2.Visible = 'off';
  71. ax2.XTick=[];
  72. ax2.YTick =[];

  73. colormap(ax1,col_h1);
  74. colormap(ax2,col_h2);

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

  80. % output
  81. h=gcf;
复制代码




file_data.tar

20.23 KB, 下载次数: 0

file_m.tar

1.75 KB, 下载次数: 0

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|Mathematica中文论坛-非官方 ( 辽ICP备16001491号-1

GMT+8, 2024-4-23 22:18 , Processed in 0.127780 second(s), 26 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表