how do i change color of the y-axes made by plotyy?
92 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Rory Staunton
am 22 Mai 2011
Kommentiert: Sharath Nagaraju
am 14 Feb. 2021
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 Kommentare
Akzeptierte Antwort
Matt Fig
am 22 Mai 2011
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 Kommentare
Karen Henneke
am 25 Feb. 2017
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
Weitere Antworten (1)
Alejandro
am 4 Apr. 2015
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 Kommentare
Sara Anthony
am 12 Jul. 2019
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')
Siehe auch
Kategorien
Mehr zu Two y-axis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!