Plotyy and line and axis color, legend
11 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Star Strider
on 1 Nov 2015
‘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.
0 Comments
See Also
Categories
Find more on Two y-axis 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!