I tried creating a plot with two YAxis like this:
x=linspace(0,20);
y1=linspace(10,10);
y2=x.^2;
y3=y2-y1;
[hAx,hLine1,hLine2]=plotyy([x',x'],[y1',y2'],x,y3);
Now i have two problem with this code:
- I can change the Linestyles of the two hLines using
hLine1.LineStyle = ':';
for example, but i can not change the styles of the two lines, that hLine1 consists of. Does anyone know how to do this? - I can't use
hLine2.YLim = [0 100]
to manually adjust the y-limits shown on the 2nd y-axis.
After I couldn't solve the problem using the plotyy
, I searched the MATLAB documentation and found another way of implementing my plot, which I thought might be easier to handle:
x=linspace(0,20);
y1=linspace(10,10);
y2=x.^2;
y3=y2-y1;
figure
hold on;
line(x,y1,'Color','r')
line(x,y2,'Color','y')
ax1 = gca;
ax2 = axes('Position',ax1.Position,'YAxisLocation','right');
line(x,y3,'Parent',ax2,'Color','b')
The problem here is, that it doesn't even show the first and the second line, but only the third and i don't know why. I would prefer getting the problem solved using the plotyy
, but if that's not possible I would appreciate a solution for the 2nd piece of code as well.