Data disappears from plot when setting axes limits?

7 views (last 30 days)
I'm trying to display a figure with three plots on it. The data in the third is of lower amplitude than the first two plots, and as such Matlab defaults to setting a smaller scale. I want to be able to set the axes limits on all three, however when I do the plots return with no data in them. I've tried moving the axes limits to what it would set them to by default and the problem still persists
My code is as follows,
figure
ax1 = subplot(3,1,1);
plot(IN1);
xlim([0 0.3]);
ylim([-0.01 0.01]);
xlabel('Time');
ylabel('Amplitude');
ax2 = subplot(3,1,2);
plot(IN2);
xlim([0 0.3]);
ylim([-0.01 0.01]);
xlabel('Time');
ylabel('Amplitude');
ax3 = subplot(3,1,3);
plot(IN3);
xlim([0 0.3]);
ylim([-0.01 0.01]);
xlabel('Time');
ylabel('Amplitude');
If I comment out the xlim & ylim functions it works fine. (See pictures below) I'm running R2015B on an Imac running macOS10.15
Any help would be greatly appreciated!

Accepted Answer

Walter Roberson
Walter Roberson on 9 Jun 2018
You have no data in the first 0.3 seconds.
You are plotting without an explicit x axis, so it is going to assume that the x axis is 1 to the length of your data, which is about 10^5 samples. Your first sample time is therefore 1. You have nothing between 0 and 0.3.
You might need something like
plot(t, IN1)
  1 Comment
Joshua Stephen
Joshua Stephen on 9 Jun 2018
Can't believe I missed the 10^5. Thanks! Forgot I was working with samples rather than seconds with this plot.

Sign in to comment.

More Answers (0)

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!