Link axes with different Y-Scales
Show older comments
I'm trying to make a plot with 2 y-axes and wasn't able to use the yyaxis command since I want to change the uistack afterwards and it doesn't work with this function showhow. Now I have a new problem because of that. When I try to link the 2 axes, the y-scale of the left axis is changed to the values of the right one that are 10 times bigger.
Is there a way to link the axes to be able to "zoom" or change the parts visible without changing the axis values?
ax2 = axes('Position',[0.1300 0.1100 0.7750 0.8150]);
ax1 = axes('Position',[0.1300 0.1100 0.7750 0.8150]);
plot(ax1,[1 5 10],[1 5 10]); % Just random values not mine
plot(ax2,[1 5 10],[10 50 100]); % Just random values not mine
ax2.YAxisLocation = 'right';
set(ax1, 'Color', 'None');
ax2.XTick = [];
linkaxes([ax1 ax2]);


Thanks for your help
2 Comments
"I'm trying to make a plot with 2 y-axes and wasn't able to use the yyaxis command since I want to change the uistack afterwards..."
There probably isn't a need to change the uistack. What exactly are you trying to do that involves the uistack? It would be cleaner to use the yyaxis function so if you could explain the problem you were having, maybe we could fix that instead of fixing the plan-b.
"Is there a way to link the axes to be able to "zoom" or change the parts visible without changing the axis values? "
It looks like the two datasets have different scales so you'll either need to
- Scale your data so the range of y values match between the two datasets, or
- don't link the axes but instead, carefully set the ylim() for each axis and the ytick.
To reiterate, I think the yyaxis solution is best and we could probably fix your uistack problem.
Alexander von Mach
on 7 Nov 2019
Accepted Answer
More Answers (0)
Categories
Find more on Axis Labels 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!