Plotyy and line and axis color, legend

조회 수: 11 (최근 30일)
Anke Kügler
Anke Kügler 2015년 11월 1일
답변: Star Strider 2015년 11월 1일
Hi,
I'm creating a plot with two lines on the y-axis and one on the secondary y-axis. I'm trying to change colors, but can't seem to get anywhere.
figure('Color',[1 1 1]);
plot(x1, y1, 'b', x2, y2,'r')
hold on;
[ax,p1, p2] = plotyy(x1,y1,x1,dx,'plot','plot');
xlabel(ax(1),'Range (m)') % label x-axis
ylabel(ax(1),'Depth (m)') % label left y-axis
ylabel(ax(2),'\delta c (m/s)') % label right y-axis
p2.LineStyle = '--';
I want the line on the secondary axis to be black .I also want to change the color of both y-axes to black.
Thank you. (Sorry, I'm still in the process of learning MatLab)
Also, If I change plotyy to
[ax,p1,p2] = plotyy(x,[y1, y2],x,dx,'plot','plot');
legend([p1;p2],'y1','y2','y3');
to handle everything in one plot, I get a figure with two axes and a legend, but none of the three graphs.
Edit:
Ok, I noticed my x1/y1 and x2/y2 vectors have different lengths. However, when I adjust that, I still don't get anything.
Can I, instead of having one x-argument und two y-arguments for the left-side y-axis have one y-argument and two x-arguments? Already tried writing it something like
[ax,p1,p2] = plotyy([x1,x2], y2,x1,dx,'plot','plot');
and
[ax,p1,p2] = plotyy([x1,y1,x2, y2],x1,dx,'plot','plot'); %different vector lengths
but neither works. I keep getting an error that "vectors must be same length" - which they are.

답변 (1개)

Star Strider
Star Strider 2015년 11월 1일
‘I want the line on the secondary axis to be black .I also want to change the color of both y-axes to black.’
That part is straightforward:
ax(1).YColor = 'k';
ax(2).YColor = 'k';
The rest I do not understand. Without your data and knowing what you want your plot to look like, it is not possible to provide specific help. You may have to experiment until you get a plot that works for you.

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by