Mathematica中文论坛-非官方

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz

豆粑粑 matlab zoom 局部放大

查看数: 13852 | 评论数: 1 | 收藏 0
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2022-3-31 21:48

正文摘要:

本帖最后由 meatball1982 于 2022-4-1 09:59 编辑 这两天只画图了。 一个图,局部放大。 之前作过,但这次的要求是要画两条线,标注两个关键的点。在matlab 中,通过一个axes, 一个新的axes, 然后在第一个axes ...

回复

meatball1982 发表于 2022-4-1 09:57:34
更新一下,通过设置第二个图为透明,直接显示第一个图中的线。

效果同附件。

  1. clear all
  2. clc
  3. clf

  4. %% outline
  5. % zoom in with line cross different axis

  6. %% main
  7. x=linspace(0,3*pi,1000);
  8. rnd = rand(size(x));

  9. y=x+exp(sin(2*x))+exp(x./3)+exp(x).*rnd/100;
  10. seedm(3)

  11. zoom =[3.8 4.3 8 14]
  12. pos1 = [0.1 0.15 0.85 0.7];
  13. pos2 = [0.2 0.4 0.3 0.25];


  14. % find line1 ends

  15. tm = x-zoom(1);
  16. [va,inbeg] = min(abs(tm));

  17. tm = x-zoom(2);
  18. [va,inend] = min(abs(tm));



  19. h=figure(1)
  20. set(h, 'Position', [1000, 1000, 550, 500]);
  21. ax11=axes('position',pos1);
  22. hold on
  23. plot(x,y,'.-')
  24. axis([0 10 -20 200])
  25. set(gca,'fontsize',14,'linewidth',2)

  26. % % % line : from corner to corner -----------------------------------------
  27. % lin1_x = [zoom(1) (0.2-0.1)/0.85 * (10-0)];
  28. % lin1_y = [zoom(3) (0.4-0.15)/0.7 * (200-(-20))-20];
  29. % lin2_x = [zoom(2) (0.2+0.3-0.1)/0.85*(10-0)];
  30. % lin2_y = [zoom(3) (0.4-0.15)/0.7 * (200-(-20))-20];

  31. % % line : from line to line -----------------------------------------
  32. lin1_x = [zoom(1) (0.2-0.1)/0.85 * (10-0)];
  33. lin1_y = [y(inbeg) ((y(inbeg)-8)*0.25/(14-8)+(0.4-0.15))/0.7 * (200-(-20))-20 ];
  34. lin2_x = [zoom(2) (0.2+0.3-0.1)/0.85*(10-0)];
  35. lin2_y = [y(inend) ((y(inend)-8)*0.25/(14-8)+(0.4-0.15))/0.7 * (200-(-20))-20];
  36. plot(lin1_x,lin1_y,'r-','linewidth',2)
  37. plot(lin2_x,lin2_y,'g-','linewidth',2)
  38. axis([0 10 -20 200])
  39. % axis off
  40. box on

  41. rectangle('Position',[zoom(1) zoom(3) zoom(2)-zoom(1) zoom(4)-zoom(3)],'linewidth',2)

  42. ax11=axes('position',pos2);
  43. plot(x,y,'.-','linewidth',2,'markersize',12)
  44. axis(zoom)
  45. set(gca,'linewidth',2)

  46. set(gcf, 'Color','none')
  47. set(gca,'color','none')


  48. % ax11=axes('position',pos1);
  49. % hold on
  50. % plot(lin1_x,lin1_y,'r-','linewidth',2)
  51. % plot(lin2_x,lin2_y,'g-','linewidth',2)
  52. % axis([0 10 -20 200])
  53. % axis off
复制代码


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

GMT+8, 2024-5-10 14:24 , Processed in 0.122531 second(s), 29 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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