Mathematica中文论坛-非官方

 找回密码
 立即注册

QQ登录

只需一步,快速开始

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

豆粑粑 matlab 断yaxis ,修改 breakYAxes.

[复制链接]

550

主题

629

帖子

3181

积分

论坛元老

Rank: 8Rank: 8

积分
3181
跳转到指定楼层
楼主
发表于 2017-5-31 10:46:20 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
别人的问题:
http://www.ilovematlab.cn/forum. ... p;extra=#pid3224636

  1. clear all
  2. clc

  3. %% outline
  4. % break y axis

  5. %% main
  6. x=linspace(0,10*pi,100);
  7. % y1 = sqrt(3)/3*x +8;
  8. y=exp(x/7)+sin(x)-30;


  9. y_break_start = 10;
  10. y_break_end = 25;
  11. break_type_w = 'Wave';
  12. % h=BreakPlot(x,y,y_break_start,y_break_end,break_type);
  13. break_type_R = 'RPatch';

  14. % figure;
  15. subplot(1,2,1)
  16. plot(x,y,'.')
  17. % subplot(2,2,2)
  18. % % BreakPlot(rand(1,21),[1:10,40:50],10,40,'Line');
  19. % h=BreakPlot(x,y,y_break_start,y_break_end,break_type_R);
  20. subplot(1,2,2)
  21. h=BreakPlot(x,y,y_break_start,y_break_end,break_type_w);
  22. % hold on
  23. % plot(x,y1,'r-')


  24. h=gcf;
  25. fi_na=['./fig_split_y_axis'];
  26. fun_work_li_035_myfig_out(h,fi_na,3);

  27. %% logs
  28. % mod : 31-May-2017 09:07:50
  29. %
复制代码


  1. function h=BreakPlot(x,y,y_break_start,y_break_end,break_type)
  2. % BreakPlot(x,y,y_break_start,y_break_end,break_type)
  3. % Produces a plot who's y-axis skips to avoid unecessary blank space
  4. %
  5. % INPUT
  6. % x
  7. % y
  8. % y_break_start
  9. % y_break_end
  10. % break_type
  11. %    if break_type='RPatch' the plot will look torn
  12. %       in the broken space
  13. %    if break_type='Patch' the plot will have a more
  14. %       regular, zig-zag tear
  15. %    if break_plot='Line' the plot will merely have
  16. %       some hash marks on the y-axis to denote the
  17. %       break
  18. %
  19. % USAGE:
  20. % figure;
  21. % BreakPlot(rand(1,21),[1:10,40:50],10,40,'Line');
  22. % figure;
  23. % BreakPlot(rand(1,21),[1:10,40:50],10,40,'Patch');
  24. % figure;
  25. % BreakPlot(rand(1,21),[1:10,40:50],10,40,'RPatch');
  26. % figure;
  27. % x=rand(1,21);y=[1:10,40:50];
  28. % subplot(2,1,1);plot(x(y>=40),y(y>=40),'.');
  29. % set(gca,'XTickLabel',[]);
  30. % subplot(2,1,2);plot(x(y<=20),y(y<=20),'.');
  31. %
  32. % IT'S NOT FANCY, BUT IT WORKS.

  33. % Michael Robbins
  34. % robbins@bloomberg.net
  35. % michael.robbins@bloomberg.net

  36. % data
  37. if nargin<5 break_type='RPatch'; end;
  38. if nargin<4 y_break_end=40; end;
  39. if nargin<3 y_break_start=10; end;
  40. if nargin<2 y=[1:10,40:50]; end;
  41. if nargin<1 x=rand(1,21); end;


  42. y_break_mid=(y_break_end-y_break_start)./2+y_break_start;
  43. [x_mid_val,ind] = min(abs(y-y_break_mid));
  44. x_break_mid = x(ind);
  45. b_shift= y_break_start-sqrt(3)/3*x_break_mid;
  46. b_shift
  47. x_break_mid
  48. y_break_mid
  49. % erase useless data
  50. x(y>y_break_start & y <y_break_end)=[];
  51. y(y>y_break_start & y <y_break_end)=[];

  52. % leave room for the y_break_end
  53. % % [junk,i]=min(y>=y_break_end);
  54. % % if i>y_break_end
  55. % %     x=[x(1:i-1) NaN x(i:end)];
  56. % %     y=[y(1:i-1) y_break_mid y(i:end)];
  57. % % end;

  58. % remap
  59. y2=y;
  60. y2(y2>=y_break_end)=y2(y2>=y_break_end)-(y_break_end-y_break_start);

  61. % plot
  62. h=plot(x,y2,'.');
  63. % h=plot(x,y,'.');

  64. % make break
  65. xlim=get(gca,'xlim');
  66. ytick=get(gca,'YTick');
  67. [junk,i]=min(ytick<=y_break_start);
  68. y=(ytick(i)-ytick(i-1))./2+ytick(i-1);
  69. dy=(ytick(2)-ytick(1))./7;
  70. xtick=get(gca,'XTick');
  71. x=xtick(1);
  72. dx=(xtick(2)-xtick(1))./2;
  73. n_int=100;
  74. switch break_type
  75.     case 'Wave',
  76.          dx=(xlim(2)-xlim(1))./10;
  77. %         xx = xlim(1)+dx.*[0:101];
  78.         xx = linspace(xlim(1),xlim(end),n_int);
  79. %         yy = sin(xx)+sqrt(3)/3*xx+ytick(i-1)+(ytick(i)-ytick(i-1))./2;
  80. %        yy =sqrt(3)/3*xx+b_shift;
  81.          yy = dx*sin(xx/6*pi)+ sqrt(3)/3*xx+b_shift;
  82.         patch([xx(:);flipud(xx(:))], ...
  83.         [yy(:)+2*dy;flipud(yy(:)-2.*dy)], ...
  84.             [1 1 1])
  85.         
  86.     case 'Patch',
  87.         % this can be vectorized
  88.         dx=(xlim(2)-xlim(1))./10;
  89.         yy=repmat([y-2.*dy y-dy],1,6);
  90.         xx=xlim(1)+dx.*[0:11];
  91.         patch([xx(:);flipud(xx(:))], ...
  92.             [yy(:);flipud(yy(:)-2.*dy)], ...
  93.             [1 1 1])
  94.     case 'RPatch',
  95.                 % this can be vectorized
  96.         dx=(xlim(2)-xlim(1))./100;
  97.         yy=y+rand(101,1).*2.*dy;
  98.         xx=xlim(1)+dx.*(0:100);
  99.                 patch([xx(:);flipud(xx(:))], ...
  100.             [yy(:);flipud(yy(:)-2.*dy)], ...
  101.             [.8 .8 .8])
  102.     case 'Line',
  103.                 line([x-dx x   ],[y-2.*dy y-dy   ]);
  104.                 line([x    x+dx],[y+dy    y+2.*dy]);
  105.                 line([x-dx x   ],[y-3.*dy y-2.*dy]);
  106.                 line([x    x+dx],[y+2.*dy y+3.*dy]);
  107. end;
  108. set(gca,'xlim',xlim);

  109. % map back
  110. ytick(ytick>y_break_start)=ytick(ytick>y_break_start)+y_break_mid;
  111. for i=1:length(ytick)
  112.    yticklabel{i}=sprintf('%4.3d',ytick(i));
  113. end;
  114. set(gca,'yticklabel',yticklabel);
复制代码


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-12-28 15:08 , Processed in 0.102676 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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