![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/285629/image.png)
Is it possible using tiledlayout to have one set of tiles with shared tight y-limits and other tiles with much larger y-limits without losing the zoomed view of tiles with tight y-limits?
20 views (last 30 days)
Show older comments
Bryan Conklin
on 18 Apr 2020
Commented: Cris LaPierre
on 27 Apr 2020
I am trying to create a figure with one set of time-series using
ylimit = [-100,100];
and another few time-series with the automatically-chosen y-limits, which are different by several orders of magnitude. Each plot shares the same x-axis limits. I want to really zoom in on the dynamics in the first set of time-series. That is the reason for the static y-limits. However, when I add the time-series which have much larger y-limits, the first set of time-series appears to zoom out and the dynamics are very difficult to see.
hf=figure; clf
chans = 16;
t = tiledlayout(chans,1,'TileSpacing','Compact','padding','compact'); %setup tile for all subplots
cmap = colormap; %get current colormap
allColors = cmap(chans:chans:chans*chans,:); %split colormap into diff colors per chan
ylimit = [-100,100]; %set y-limit for zoomed-in view of dynamics
for subplotN=1:chans-3 %plot first set of time-series
nexttile
x = 1:2841;
y = randn(1,2841)*50;
plot(x,y,'LineWidth',2,'Color',allColors(subplotN,:))
ylim(ylimit)
end
This code yields the following figure. Looks decent, I can see the dynamics:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/285598/image.png)
Now, I add the next time-series with a ylimit that is several orders of magnitude different
nexttile
y1 = randn(1,2841)*1e6;
plot(x,y1,'LineWidth',2,'Color','b');
This causes the previous traces to zoom out so it's way harder to see their dynamics:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/285599/image.png)
How can I fix this? I want the previous time-series to stay zoomed-in as I add the remaining tiles with significantly larger ylimits.
Thank you in advance for any help.
0 Comments
Accepted Answer
Cris LaPierre
on 18 Apr 2020
To me, it appears the previous timeseries YAxis Limits have not changed (i.e. it is still "zoomed in"). I think what has happened is that, by adding a plot requiring an exponent to capture the scale of the Y values (x10^6), the actual height of each plot has also shrunk to to accomodate an exponent. The fix is to find a way to plot the data without adding the exponent for the larger scale variables.
One approach may be to divide by whatever the explonent is.
nexttile
y1 = randn(1,2841)*1e6;
% find exponent automatically and divide y1 by it when plotting
x10=floor(log10(max(y1)))
plot(x,y1/10^x10,'LineWidth',2,'Color','b')
I wonder if stackedplot might be a better option for you. You'd have to modify your code a little, and wouldn't be able to color each line (at least not easily), but it does a better job keeping the y-axes as tall as possible.
figure;
chans = 16;
for subplotN=1:chans-3 %plot first set of time-series
x = 1:2841;
y(:,subplotN) = randn(2841,1)*50;
end
y(:,subplotN+1) = randn(1,2841)*1e6;
stackedplot(x,y)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/285629/image.png)
4 Comments
Cris LaPierre
on 27 Apr 2020
Another thought. Another althernative might be forcing the exponent to be 0. Perhaps that is more desireable than dividing by 10e^10, especially if you actually don't know what the maximum magnitude to be encountered will be.
ax = gca;
ax.YAxis.Exponent = 0;
You can then use ytickformat to set the formatting if you want.
More Answers (0)
See Also
Categories
Find more on Line Plots 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!