Matlab进阶绘图第12期—局部放大图

最近资源群里有好几个朋友问我该如何对一幅图上的局部区域进行放大展示,从而可以更好地描绘细节信息……

于是,便有了本期内容。

局部放大图的绘制方法有很多,但为了使用方便,本文直接利用BaseZoom工具(Kepeng Qiu. Matlab Central, 2022)进行局部放大图的绘制,先来看一下成品效果:

特别提示:本期内容『数据+代码』已上传资源群中,加群的朋友请自行下载。有需要的朋友可以关注同名公号【阿昆的科研日常】,后台回复关键词【绘图桶】查看加入方式。


1. 初始数据图绘制

此部分主要是绘制初始数据图

%% 数据准备% 导入数据load data xfit yfit xdata_m ydata_m ydata_s xVdata yVdata xmodel ymodel ...    ymodelL ymodelU c cint%% 颜色定义% TheColor函数获取方式:% 公众号后台回复:TCcolor_hFit = TheColor('xkcd',346);color_hModel = TheColor('xkcd',545);color_hData = TheColor('xkcd',301);color_hCI1 = TheColor('xkcd',304);color_hCI2 = TheColor('xkcd',304);color_hE = TheColor('xkcd',587);%% 图片尺寸设置(单位:厘米)figureUnits = 'centimeters';figureWidth = 15;figureHeight = 12;%% 窗口设置figureHandle = figure;set(gcf, 'Units', figureUnits, 'Position', [0 0 figureWidth figureHeight]); % define the new figure dimensionshold on%% 绘制hFit = line(xfit, yfit);hData = line(xVdata, yVdata);hModel = line(xmodel, ymodel);hCI(1) = line(xmodel, ymodelL);hCI(2) = line(xmodel, ymodelU);hE = errorbar(xdata_m, ydata_m, ydata_s);% 添加labelhTitle = title('My Publication-Quality Graphics');hXLabel = xlabel('Length (m)');hYLabel = ylabel('Mass (kg)');% 添加文字注释hText = text(10, 800, ...    sprintf('{\\itC = %0.1g \\pm %0.1g (CI)}', c, cint(2)-c));%% 细节优化% 赋色set(hFit, 'Color', color_hFit)set(hModel, 'Color', color_hModel)set(hCI(1), 'Color', color_hCI1)set(hCI(2), 'Color', color_hCI2)set(hData, 'MarkerEdgeColor', 'none', 'MarkerFaceColor', color_hData)set(hE, 'Color', color_hE, 'MarkerEdgeColor', [.2 .2 .2], 'MarkerFaceColor' , color_hE)% 设置线属性set(hFit, 'LineWidth', 1.5)set(hModel, 'LineStyle', '--', 'LineWidth', 1.5)set(hCI(1), 'LineStyle', '-.','LineWidth', 1.5)set(hCI(2), 'LineStyle', '-.','LineWidth', 1.5)set(hData, 'LineStyle', 'none', 'Marker', '.','Marker', 'o', 'MarkerSize', 5)set(hE, 'LineStyle', 'none', 'Marker', '.','LineWidth', 1.5, 'Marker', 'o', 'MarkerSize', 6)% 设置坐标轴属性set(gca, 'Box', 'off',...          'TickDir', 'out', 'TickLength', [.01 .01], ...         'XMinorTick', 'on', 'YMinorTick', 'on',...          'XGrid', 'off', 'YGrid', 'off', ...         'XColor', [.3 .3 .3], 'YColor', [.3 .3 .3],...         'YTick', 0:500:2500, ...         'LineWidth', 1)% 添加上、右框线hold onXL = get(gca,'xlim'); XR = XL(2);YL = get(gca,'ylim'); YT = YL(2);xc = get(gca,'XColor');yc = get(gca,'YColor');plot(XL,YT*ones(size(XL)),'color', xc,'LineWidth',1)plot(XR*ones(size(YL)),YL,'color', yc,'LineWidth',1)% legendhLegend = legend([hE, hFit, hData, hModel, hCI(1)], ...    'Data ({\it\mu} \pm {\it\sigma})', 'Fit (C{\itx}^3)', ...    'Validation Data', 'Model (C{\itx}^3)', '95% CI', ...    'Location', 'SouthEast');% 设置字体字号set(gca, 'FontName', 'Helvetica')set([hTitle, hXLabel, hYLabel, hText], 'FontName', 'AvantGarde')set([hLegend, gca], 'FontSize', 8)set([hXLabel, hYLabel, hText], 'FontSize', 10)set(hTitle, 'FontSize', 12, 'FontWeight' , 'bold')% 背景颜色set(gcf,'Color',[1 1 1])

2. 局部放大图绘制

初始数据图绘制完成后,调用BaseZoom工具

%% 添加局部放大zp = BaseZoom();zp.plot;

通过鼠标左键框选作图区域

鼠标右键确定后,通过鼠标左键框选需要放大的区域

鼠标右键确定后,完成局部放大图的绘制。

以上。

  • 2
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值