Plotyy and line and axis color, legend

12 次查看(过去 30 天)
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