MATLAB图中图绘制(局部放大图)

方法1 使用magnify工具

magnify工具可以实现对绘制的figure手动选择区域,并且可以选择多个放大区域。

  1. 下载magnify.m,可以点击上面的链接下载或者可以拷贝附件的代码,保存为magnify.m。然后放到工作目录下(也就是和绘图的程序同一目录。)
  2. 绘制一张图figure.
  3. 保证前两个工作完成,输入magnify,接着就可以选择放大区域了,右键选中想要放大的区域,可以使用‘<’和‘>’缩放方法范围,‘+’和‘-’缩放放大比例,松开右键确认。
  4. 可以通过工具->编辑图形调整子图位置等。

方法2 手动绘制

  此方法需要通过手动设置绘制的数据,具体的说就是需要哪一段就提取某一段的数,通过matlab自带的axes绘制子图。

clc;clear;close all;
t=linspace(0,3,100);
t1=linspace(1,1.2,100);
y=sin(t);
y1=sin(t1);
figure;                                   % 大图
plot(t,y);
axis('equal');
axes('Position',[0.2,0.5,0.3,0.3]);   % 小图 设置小图的大小和位置(左上角位置+宽高)
plot(t1,y1);
xlim([min(t1),max(t1)]);

附件 magnify.m(来源于matlab官网)

function magnify(f1)
%
%magnify(f1)
%
%  Figure creates a magnification box when under the mouse
%  position when a button is pressed.  Press '+'/'-' while
%  button pressed to increase/decrease magnification. Press
%  '>'/'<' while button pressed to increase/decrease box size.
%  Hold 'Ctrl' while clicking to leave magnification on figure.
%
%  Example:
%     plot(1:100,randn(1,100),(1:300)/3,rand(1,300)), grid on,
%     magnify;% Rick Hindman - 7/29/04if (nargin == 0), f1 = gcf; end;
set(f1, ...'WindowButtonDownFcn',  @ButtonDownCallback, ...'WindowButtonUpFcn', @ButtonUpCallback, ...'WindowButtonMotionFcn', @ButtonMotionCallback, ...'KeyPressFcn', @KeyPressCallback);
return;function ButtonDownCallback(src,eventdata)f1 = src;a1 = get(f1,'CurrentAxes');a2 = copyobj(a1,f1);set(f1, ...'UserData',[f1,a1,a2], ...'Pointer','fullcrosshair', ...'CurrentAxes',a2);set(a2, ...'UserData',[2,0.2], ...  %magnification, frame size'Color',get(a1,'Color'), ...'Box','on');xlabel(''); ylabel(''); zlabel(''); title('');set(get(a2,'Children'), ...'LineWidth', 2);set(a1, ...'Color',get(a1,'Color')*0.95);set(f1, ...'CurrentAxes',a1);ButtonMotionCallback(src);
return;function ButtonUpCallback(src,eventdata)H = get(src,'UserData');f1 = H(1); a1 = H(2); a2 = H(3);set(a1, ...'Color',get(a2,'Color'));set(f1, ...'UserData',[], ...'Pointer','arrow', ...'CurrentAxes',a1);if ~strcmp(get(f1,'SelectionType'),'alt'),delete(a2);end;
return;function ButtonMotionCallback(src,eventdata)H = get(src,'UserData');if ~isempty(H)f1 = H(1); a1 = H(2); a2 = H(3);a2_param = get(a2,'UserData');f_pos = get(f1,'Position');a1_pos = get(a1,'Position');[f_cp, a1_cp] = pointer2d(f1,a1);set(a2,'Position',[(f_cp./f_pos(3:4)) 0 0]+a2_param(2)*a1_pos(3)*[-1 -1 2 2]);a2_pos = get(a2,'Position');set(a2,'XLim',a1_cp(1)+(1/a2_param(1))*(a2_pos(3)/a1_pos(3))*diff(get(a1,'XLim'))*[-0.5 0.5]);set(a2,'YLim',a1_cp(2)+(1/a2_param(1))*(a2_pos(4)/a1_pos(4))*diff(get(a1,'YLim'))*[-0.5 0.5]);end;
return;function KeyPressCallback(src,eventdata)H = get(gcf,'UserData');if ~isempty(H)f1 = H(1); a1 = H(2); a2 = H(3);a2_param = get(a2,'UserData');if (strcmp(get(f1,'CurrentCharacter'),'+') | strcmp(get(f1,'CurrentCharacter'),'='))a2_param(1) = a2_param(1)*1.2;elseif (strcmp(get(f1,'CurrentCharacter'),'-') | strcmp(get(f1,'CurrentCharacter'),'_'))a2_param(1) = a2_param(1)/1.2;elseif (strcmp(get(f1,'CurrentCharacter'),'<') | strcmp(get(f1,'CurrentCharacter'),','))a2_param(2) = a2_param(2)/1.2;elseif (strcmp(get(f1,'CurrentCharacter'),'>') | strcmp(get(f1,'CurrentCharacter'),'.'))a2_param(2) = a2_param(2)*1.2;end;set(a2,'UserData',a2_param);ButtonMotionCallback(src);end;
return;% Included for completeness (usually in own file)
function [fig_pointer_pos, axes_pointer_val] = pointer2d(fig_hndl,axes_hndl)
%
%pointer2d(fig_hndl,axes_hndl)
%
%   Returns the coordinates of the pointer (in pixels)
%   in the desired figure (fig_hndl) and the coordinates
%       in the desired axis (axes coordinates)
%
% Example:
%  figure(1),
%  hold on,
%  for i = 1:1000,
%     [figp,axp]=pointer2d;
%     plot(axp(1),axp(2),'.','EraseMode','none');
%     drawnow;
%  end;
%  hold off% Rick Hindman - 4/18/01if (nargin == 0), fig_hndl = gcf; axes_hndl = gca; end;
if (nargin == 1), axes_hndl = get(fig_hndl,'CurrentAxes'); end;set(fig_hndl,'Units','pixels');pointer_pos = get(0,'PointerLocation');   %pixels {0,0} lower left
fig_pos = get(fig_hndl,'Position');  %pixels {l,b,w,h}fig_pointer_pos = pointer_pos - fig_pos([1,2]);
set(fig_hndl,'CurrentPoint',fig_pointer_pos);if (isempty(axes_hndl)),axes_pointer_val = [];
elseif (nargout == 2),axes_pointer_line = get(axes_hndl,'CurrentPoint');axes_pointer_val = sum(axes_pointer_line)/2;
end;

MATLAB图中图绘制(局部放大图)相关推荐

  1. 在MATLAB的figure图中画局部放大的图中图

    在MATALB绘图中,有时会遇到这样的情况,需要通过放大figure图的局部,针对细节加以说明.例如:在给定的尺度下有两条或多条曲线难以区别,此时就需要对其进行局部放大来加以区分.参考网上的解决方法1 ...

  2. MATLAB中使用magnify做图中图

    网上一般有三种方法在MATLAB中做图中图,但是我感觉使用magnify是magnify是个动态放大镜,固化后可以用tools>edit plot移动小图,能选取多个局部图.下面详细讲解其使用方 ...

  3. plt.figure、plt.subplot介绍以及绘制图中图(含代码)

    目录 1.1 plt.figure()函数语法介绍 1.2 figure实例 2.1 subplot函数及其语法说明 2.2 用subplot画多个子图 3.1 subplots函数介绍 4.1 使用 ...

  4. matlab画一个局部放大的图中图

    局部放大的图中图 第一种:magnify是个动态放大镜,固化后可以用tools>editplot移动小图,能选取多个局部图,这个方法不错 用法:打开figure图,输入magnify,左键动态选 ...

  5. 14_面向对象API绘图、图中图 (A Plot inside of Another Plot)、设定绘图范围Setting the Plot Range、对数尺度Logarithmic Scale

    14.面向对象API绘图 14.1.图中图 (A Plot inside of Another Plot) 14.2.设定绘图范围 (Setting the Plot Range) 14.3.对数尺度 ...

  6. Python画图(直方图、多张子图、二维图形、三维图形以及图中图)

    Python画图很方便,不管是平时的学习还是教学当中,都将经常用到,特别直观,其中主要用到两个常用的库,一个二维和三维的:matplotlib.pyplot,mpl_toolkits.mplot3d ...

  7. Python利用matplotlib做图中图及次坐标轴

    图中图 准备数据 import matplotlib.pyplot as pltfig = plt.figure() x = [1, 2, 3, 4, 5, 6, 7] y = [1, 3, 4, 2 ...

  8. chatgpt赋能python:Python中的图中图:什么是图中图?如何使用?

    Python中的图中图:什么是图中图?如何使用? 在Python中的数据可视化中,图中图是一种非常有用的工具,它可以帮助我们以一种清晰而有用的方式展示更多的信息.从字面上看,图中图意味着图形中包含另一 ...

  9. python(matplotlib8)——图中图(在figure中画多个坐标图),次坐标(两个y轴)

    文章目录 前言 图中图 次坐标(两个y轴) 前言 来自 莫烦python的总结. 图中图 left,bottom,width,height = 百分比 fig = plt.figure() x = [ ...

  10. ARCGIS制作图中图——小图/一幅多图

    文章目录 1.中国完整政区的shape文件制作 2 制作图中图 2.1 选择目标区域 2.2 选择目标区域 2.3 创建研究区shapefile 2.3 创建研究区shapefile 3 最后的小调整 ...

最新文章

  1. 新手入门API测试必要了解的知识
  2. 电商系统的售后模块设计
  3. java编程有什么独特之处?
  4. 苹果将允许应用用户转至Web端付费,免除30% 佣金
  5. 什么是利用计算机化的知识进行自动推理,基于实例模型的知识推理及其在自动阅卷系统中的应用...
  6. 百面机器学习 #3 经典算法:02 逻辑回归
  7. html+分割字符,sql拆分字符串split
  8. RFID--Radio frequency Identification
  9. ESP8266开发之旅 应用篇② OLED显示天气屏
  10. FIR versus IIR Butterworth Chebyshev Bessel Filter
  11. Googel浏览器添加百度搜索引擎
  12. 在计算机中添加用户时提示拒绝访问,教你怎么解决打印机拒绝访问问题
  13. 哈尔滨学院Day2--A The Puzzle
  14. 2016中国移动CRM洞察力论坛召开|码客荣获2016中国移动CRM产品创新奖
  15. win10右键一直卡死解决记录
  16. 【luogu P4036】【ybt金牌导航4-5-3】火星人
  17. 经纬度和球体三维坐标换算
  18. 国产arm芯片CH32F103芯片 CH32F103C8T6 如何下载程序
  19. 微软.net精简框架最常见问题
  20. Elasticsearch 性能优化指引(十八)

热门文章

  1. 算法注册机编写扫盲之续篇---第三课
  2. TypeError this.getOptions is not a function 的解决
  3. 中兴阅读在期刊杂志数字化、移动化上的探索
  4. python编写贪吃蛇大战_用Python实现贪吃蛇双人大战
  5. 裸眼 3D 技术是什么原理?
  6. matlab方波函数,matlab方波
  7. php做网络心理测试,php心理测试程序源代码版,求高手帮忙写一个c语言的心理测试程序...
  8. 腾讯云服务器放音乐,使用腾讯云函数实现网易云音乐自动打卡签到
  9. JS调用Arcgis实现地图中心点画圆
  10. 中文拼写纠错_一种中文拼写检查方法与流程