Search code examples
matlabzoomingsubplot

Matlab: Plots and Subplots - How do I make Matlab zoom into all the subplots simultaneously?


I have multiple sub-plots. When I zoom into the first subplot to view a certain data set Matlab does not zoom the rest of the subplots. How do I make Matlab zoom into all subplots simultaneously?

subplot(2,1,1)
hold on
plot(Tim1.in,IA1.raw32SPC,'b-')
hold off

subplot(2,1,2)
hold on
plot(Tim1.in,IA1.cos,'r-*')
hold off

Solution

  • Since the x variable is the same, It makes sense to just link the x axes in this case. I added some code to create the x and y variables so that anyone can run the code below. You were also using hold unnecessarily.

    x = 1:10;
    y1 = 3*x;
    y2 = x.^2;
    ax(1) = subplot(2,1,1);
    plot(x, y1, 'b-')
    
    ax(2) = subplot(2,1,2);
    plot(x, y2, 'r-*')
    linkaxes(ax, 'x')