缩放图形中的一部分图形-Matlab

Zooming a portion of figure in a figure-Matlab

我有一个带对数轴的散点图,我想在原始图上添加一个小图,放大图的特定部分。是这样的:

但是对于此图上此代码的特定部分:

X2=rand(1,100);
Y2=rand(1,100);
p2=rand(1,100);
W_esc_half=rand(1,100);
scatter(X2,Y2)
hold on; 
plot(W_esc_half,p2,'r','LineWidth',2)



  set(gca, 'xScale', 'log')
    set(gca, 'YScale', 'linear')

试试这个 - 插图基本上是一个新的轴对象,用户指定 xlimylim

X2=rand(1,100);
Y2=rand(1,100);
p2=rand(1,100);
W_esc_half=rand(1,100);
scatter(X2,Y2)
hold on;
plot(W_esc_half,p2,'r','LineWidth',2)
set(gca, 'xScale', 'log')
set(gca, 'YScale', 'linear')

% creating the zoom-in inset
ax=axes;
set(ax,'units','normalized','position',[0.2,0.2,0.2,0.2])
box(ax,'on')
plot(W_esc_half,p2,'r','LineWidth',2,'parent',ax)
set(ax,'xlim',[0.2,0.3],'ylim',[0.2,0.4])