how do i change color of the y-axes made by plotyy?
조회 수: 92 (최근 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;
댓글 수: 0
채택된 답변
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
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
추가 답변 (1개)
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
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 Center 및 File Exchange에서 Two y-axis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!