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

92 vues (au cours des 30 derniers jours)
Rory Staunton
Rory Staunton le 22 Mai 2011
Commenté : Sharath Nagaraju le 14 Fév 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;

Réponse acceptée

Matt Fig
Matt Fig le 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 commentaires
Karen Henneke
Karen Henneke le 25 Fév 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
Timothy Reilly
Timothy Reilly le 10 Juil 2019
I agree. Help is getting to be a bubbling swamp like Microsoft help.

Connectez-vous pour commenter.

Plus de réponses (1)

Alejandro
Alejandro le 4 Avr 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 commentaires
Sara Anthony
Sara Anthony le 12 Juil 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')
Sharath Nagaraju
Sharath Nagaraju le 14 Fév 2021
@Sara Anthony Code was really helpful

Connectez-vous pour commenter.

Catégories

En savoir plus sur Two y-axis dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by