Setting y-axes range on plot with multiple x- axes

1 view (last 30 days)
Hi! I'm having some issues regarding a plot with two x-axes and a similar y-axis. At least, that's what I want. My code from matlab looks like this:
t1 = [1:length(q_mean_norm)];
t2 = [1:length(q_mean_pc_dt_zero)];
figure(3)
xlabels{1} = 'q_mean_norm valid samples[s]';
xlabels{2} = 'q_mean_pc_dt_zero valid samples[s]';
ylabels{1} = 'Flow [l/min]';
ylabels{2} = 'Flow [l/min]';
[ax,hl1,hl2] = plotxx(t1,q_mean_norm,t2,q_mean_pc_dt_zero,xlabels,ylabels);
grid;
The problem is that my two y-axes in this case are different. The two functions have minor differences which in this case could be neglected. Hence it would be favourable to keep the y-axes limits the same, in this case [-100,2000], regardeless of the fact that the two x-axes don't match.
I've tried different commands to manipulate both y-axes without any luck. Any tips you got? Thanks!

Accepted Answer

dpb
dpb on 15 Dec 2014
Edited: dpb on 16 Dec 2014
...keep the y-axes limits the same, in this case [-100,2000]...
set(ax,'ylim',[-100 2000])
Alternatively, you can use linkaxes and then manipulate only one and the other will follow...
linkaxes(ax,'y')
ylim(ax(1),[-100 2000])
For some reason I've never fathomed, [x|y]ylim don't accept a vector of handles; you have to use set to do more than one at a time. linkaxes then lets you do just the one and use ylim as demonstrated but it's not a lot of help overall in reducing code as you then have to use the specific axes handle.

More Answers (0)

Categories

Find more on 2-D and 3-D 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!