how do i change color of the y-axes made by plotyy?

174 次查看(过去 30 天)
I am trying to make the color of the left Y axis red and the color of the right Y axis blue. I can't figure out the right syntax.
Thanks in advance.
A snip of the code I have is below:
close;
% plot F23 vs. D in figure gcf
[AX,H1,H2]=plotyy(Dcurve,F23curve,W,V,'plot');
AX
set(gcf,'Position',[500,500,900,500]);
title('Click on all the discontinuities and then hit Return key');
set(get(AX(1),'Ylabel'),'String','Force^(2/3) [N^(2/3)]');
% ? % set(get(AX(1),'color'),'red');
set(get(AX(2),'Ylabel'),'String','Force [N]');
% ? % set(get(AX(2),'color'),'blue');
xlabel('Indentation depth [m]');
set(H1,'LineStyle','-');
set(H1,'color','red');
set(H2,'LineStyle','-');
set(H2,'color','blue');
hold on
% user double click on all discontinuities and press enter
[xm,ym]=ginput;

采纳的回答

Matt Fig
Matt Fig 2011-5-22
An example:
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
[AX,H1,H2] = plotyy(x,y1,x,y2,'plot');
set(AX,{'ycolor'},{'r';'b'}) % Left color red, right color blue...
  4 个评论
Karen Henneke
Karen Henneke 2017-2-25
It sure would be nice if matlab would go back to help as they used to do it 10 or so years ago---one could find what they needed easily---now it is hard to find anything you need in matlab help
Timothy Reilly
Timothy Reilly 2019-7-10
I agree. Help is getting to be a bubbling swamp like Microsoft help.

请先登录,再进行评论。

更多回答(1 个)

Alejandro
Alejandro 2015-4-4
I'm using this:
% removing ticks and everything else
% for x
set(gca,'XTickLabel',[])
set(gca,'XTick',[])
set(gca,'xcolor','w')
% for y
set(gca,'YTickLabel',[])
set(gca,'YTick',[])
set(gca,'ycolor','w')
% for z
set(gca,'ZTickLabel',[])
set(gca,'ZTick',[])
set(gca,'zcolor','w')
seems that it works pretty well, leaving just the with box in the background.
  5 个评论
Sara Anthony
Sara Anthony 2019-7-12
I know this is really old, but I wanted to leave a comment that might help someone else. Alejandro's answer works the best for me. However, it's likely because I'm already using that format for the rest of my code:
yyaxis left
errorbar(Wr2IsotDateNum(1:22,1),Wr2D18O(1:22,1),ErrWr2D18O(1:22),'*--k')
ylim([-8.6 -7.5])
ytickformat('%.1f')
set(gca,'ycolor','k')
yyaxis right
plot(W2DateNum(22468:22598,1),M5Wr2C,'b')
set(gca,'ycolor','b')
ylim([0.64 0.7])
ytickformat('%.2f')

请先登录,再进行评论。

类别

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