曲线折叠
clear ;
close all;
%正常绘图
x=0:0.005:5;
y=exp(-6*x).*sin(x*40)*6+exp(5*x)*5e-11.*sin(x*20);
figure(1)
for i=1:2
a(i)=subplot(2,1,i);
title('Before');
plot(x,y,x,y+2,'o');
grid on;
title('Before');
legend('a','a+2');
xlim([0 5]);
end
drawnow;
cutout(a(2),1,4,0.2);
%将a(2)的1到4部分折叠为长度0.2的虚线段
title('After');
折叠曲线的函数
function cutout(axes_handle,Start,End,Gap)
xt=axes_handle.XTick;
xl=axes_handle.XLim;
p=allchild(axes_handle);
px={p.XData};
py={p.YData};
leg=findobj(axes_handle.Parent,'Tag','legend');
[leg.AutoUpdate]=deal('off');
kolor={p.Color};
hold on;
for i=1:length(p)
p(i).XData=px{i}(1:find(px{i}>=Start,1));
p(i).YData=py{i}(1:find(px{i}>=Start,1));
x{i}=px{i}(find(px{i}>=End,1):end)-End+Start+Gap;
y{i}=py{i}(find(px{i}>=End,1):end);
pl(i,:)=plot(x{i},y{i},[p(i).XData(end) x{i}(1)],[p(i).YData(end) y{i}(1)],...
'Color',kolor{i});
pl(i,2).LineStyle=':';
pl(i,1).Marker=p(i).Marker;
pl(i,1).MarkerSize=p(i).MarkerSize;
pl(i,1).LineWidth=p(i).LineWidth;
end
hold off;
xta=xt(1:find(xt>=Start));
xta(end)=Start;
xtb=xt(find(xt>End):end);
xtb=[End xtb];
xtL=[xta xtb];
xt2=[xta xtb-End+Start+Gap];
axes_handle.XTick=xt2;
axes_handle.XTickLabel=xtL;
axes_handle.XLim=[xl(1) xl(2)-End+Start+Gap];
end
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有