2

I have a scatter plot with logarithmic axes and I want to add a small figure on the original figure which zooms on a specific part of the plot. Something like this : enter image description here

but for a specific part of this code on this graph:

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')
  • 1
    Yes, interesting! I was also always looking for a way to mimic the `spy` package from *pgfpots/tikz* in MATLAB – max Apr 04 '20 at 05:54

1 Answers1

0

try this - the inset is basically a new axes object with user specified xlim and ylim

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])
FangQ
  • 1,444
  • 10
  • 18