【亲测有效】
在作图过程中,如果想将局部信息展示出来并且画在同一张图中,一般的MATLAB作图法就比较拙计了,好在MATLAB还是很强大的,当然,除了不能当女朋友之外 .... ╮(╯▽╰)╭
function showdetail()
% 在当前的axes上操作,用矩形框选出感兴趣的一
% 块区域然后在现有的axes里新建一axes将其画出
set(gcf,'color','white');
% 拿到axes在figure中的坐标值及其刻度值分布范围
Pos = get(gca,'Position');
X0 = Pos(1);
Y0 = Pos(2);
DX = Pos(3);
DY = Pos(4);
DLX = xlim;
DLY = ylim;
% 拿到axes中曲线数据
h = findobj(gcf,'Type','line');
xdata = get(h,'XData');
ydata = get(h,'YData');
Color = get(h,'Color');
LineStyle = get(h,'LineStyle');
LineWidth = get(h,'LineWidth');
Marker = get(h,'Marker');
MarkerSize = get(h,'MarkerSize');
MarkerEdgeColor = get(h,'MarkerEdgeColor');
MarkerFaceColor = get(h,'MarkerFaceColor');
% 选取需要放大显示的细节部分ROI
h1 = imrect; % 框选出需要的区域
wait(h1);
pos = getPosition(h1); % 返回区域的位置和大小
x0 = pos(1);
y0 = pos(2);
dx0 = pos(3);
dy0 = pos(4);
% 细节部分的下标
if iscell(xdata) == 0
indx1 = find( xdata >= x0 );
indx2 = find( xdata <= x0+dx0 );
indx = indx1(1):indx2(end);
else
m = length(xdata);
indx1 = find( xdata{1}>=x0 );
indx2 = find( xdata{1}<=x0+dx0 );
indx = indx1(1):indx2(end);
end
hold on;
LineX = x0:dx0/10:x0+dx0;
LineY = y0:dy0/10:y0+dy0;
plot(LineX,y0*ones(size(LineX)),'k');
plot(LineX,(y0 + dy0)*ones(size(LineX)),'k');
plot(x0*ones(size(LineY)),LineY,'k');
plot((x0+dx0)*ones(size(LineY)),LineY,'k');
h2 = imrect;
wait(h2);
pos = getPosition(h2);
x = pos(1);
y = pos(2);
dx = pos(3);
dy = pos(4);
xn = X0 + DX*(x - DLX(1))/( DLX(2) - DLX(1) );
yn = Y0 + DY*(y - DLY(1))/( DLY(2) - DLY(1) );
dxn = DX*dx / ( DLX(2) - DLX(1) );
dyn = DY*dy / ( DLY(2) - DLY(1) );
delete(h1);
delete(h2);
axes('Position', [xn yn dxn dyn]);
if iscell(xdata) == 0
plot(xdata(indx),ydata(indx),...
'Color',Color,...
'LineStyle',LineStyle,...
'LineWidth',LineWidth,...
'Marker',Marker,...
'MarkerSize',MarkerSize,...
'MarkerEdgeColor',MarkerEdgeColor,...
'MarkerFaceColor',MarkerFaceColor);
else
for i = 1:m
plot(xdata{i}(indx),ydata{i}(indx),...
'Color',Color{i},...
'LineStyle',LineStyle{i},...
'LineWidth',LineWidth{i},...
'Marker',Marker{i},...
'MarkerSize',MarkerSize{i},...
'MarkerEdgeColor',MarkerEdgeColor{i},...
'MarkerFaceColor',MarkerFaceColor{i});
hold on;
end
end
set( gca , 'Box', 'off');
axis([x0 x0+dx0 y0 y0+dy0]);
hold off;
end
先准备好一张图,然后直接在命令行里运行
showdetail();
然后分为如下几部操作:
【1】这是事先准备好的一张图
【2】运行程序后选择ROI,即感兴趣的区域,双击左键确定
【3】选择你想要放置的地方,双击左键确定
【4】成品图
再次感受到了MATLAB的强大。。。。。当然,这里并没讲什么气泡动力学,只是借用了一张数值解的图......( ̄▽ ̄).....,下一章应该会讲一讲瑞利气泡动力学 ( ̄︶ ̄)