How do I divide my y axis into sections / exclude a region of the y axis from plotting?
Show older comments
I have essentially a square wave that I want to plot, but I only care about what happens at the bottom and top of the square wave. I'd like to split my y axis into two portions that display a range around the maximum of the square wave and the minimum of the square wave.
One option that I already know of is to use subplots:
subplot(2,1,1)
plot(x,y)
ylim([0.99 1.01]
subplot(2,1,2)
plot(x,y)
ylim([-1.01 -0.99])
But I would rather have the data on one axis so that it's easier visually to see what's going on. Is there a way to do this?
Answers (2)
Azzi Abdelmalek
on 24 Mar 2014
x=0:.1:10;
y=1.01*sin(x)
[ax,h1,h2]=plotyy(x,y,x,y)
set(ax(1),'ylim',[0.99 1.01])
set(ax(2),'ylim',[-1.01 -0.99])
1 Comment
Travis
on 24 Mar 2014
Edited: Azzi Abdelmalek
on 25 Mar 2014
Star Strider
on 24 Mar 2014
My suggestion:
x = linspace(0,10);
y1 = [x(1:50) 10-x(51:100)]; % Generate triangle
figure(1)
plot(x,y1) % Plot entire triangle
grid
yL = y1;
yH = y1;
yL(yL>1.5) = NaN; % Vanish everything > 1.5 in ‘yL’
yH(yH<3.5) = NaN; % Vanish everything < 3.5 in ‘yH’
yC = [yL; yH-2*ones(size(yH))]; % Combine ...
figure(2)
plot(x, yC)
grid
Salt to taste...
2 Comments
Travis
on 25 Mar 2014
Star Strider
on 25 Mar 2014
Seems I wasn’t clear on what you wanted. I’m glad you found a solution.
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!