Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting multiple series in matlab

Tags:

plot

matlab

The following commands produce some very strange results -

 plotyy(1:3,2:4,3:5,4:6)
hold on
plotyy(1:3,2.1:4.1,3:5,4.1:6.1)

I basically want to plot two different series on the left y axes and two more series on the right y axes. The above commands work fine for the left series, but produce weird results for the right one. The second green line doesn't look like it should.

like image 507
Rohit Pandey Avatar asked Dec 20 '22 22:12

Rohit Pandey


1 Answers

The problem that you are having is related to the way that the plotyy creates they plot. plotyy creates two different axes that it plots on, and then mounts them into a single figure. When you issue the hold on command, you are only freezing one of the axes. To fix this, you need to hold each one individually, and then plot back onto them using the plot command.

[ax,hl,hr] = plotyy(1:3,2:4,3:5,4:6);
hold(ax(1), 'on')  
hold(ax(2), 'on')
plot(ax(1), 1:3,2.1:4.1) 
plot(ax(2), 3:5,4.1:6.1)
like image 92
slbass Avatar answered Jan 02 '23 21:01

slbass