Plot Overlay MATLAB

ServAce85 picture ServAce85 · Nov 16, 2009 · Viewed 15k times · Source

How do you take one plot and place it in the corner (or anywhere for that matter) of another plot in MATLAB?

I have logarithmic data that has a large white space in the upper right-hand side of the plot. In the white space I would like to overlay a smaller plot containing a zoomed in version of the log plot in that white space (sort of like a magnified view).

Before you tell me it can't be done, I would like to mention that I have seen it in action. If my description is lacking, just let me know and I'll attempt to better describe it to you.

Answer

Amro picture Amro · Nov 16, 2009

An example:

x = 1:20;
y = randn(size(x));

plot(x, y,'LineWidth',2)
xlabel('x'), ylabel('y'), title('Plot Title')

h = axes('Position', [.15 .65 .2 .2], 'Layer','top');
bar(x,y), title('Bar Title')
axis(h, 'off', 'tight')

screenshot