Why does ycolor also color the xaxis?

11 views (last 30 days)
After using plotyy, the ycolor command turns the left yaxis blue, right yaxis red and the xaxis red. I want xaxis to remain black. Using xcolor has no effect.
set(gca,{'ycolor'},{'b';'r'})

Accepted Answer

Dave B
Dave B on 1 Feb 2022
With plotyy, you can use the output arguments to get access to the 'right' axes. Setting the property on gca would just affect the left axis (and I'd have expected an error with the syntax you provided):
ax=plotyy(1:10,1:10,1:10,ones(1,10));
set(ax(1),'YColor','b');
set(ax(2),'YColor','r');
Note that as you'll see on the plotyy documentation page, plotyy is not recommended, and we suggest you use yyaxis instead. Here is the equivalent code using yyaxis:
figure
yyaxis left
plot(1:10,1:10);
set(gca,'YColor','b')
yyaxis right
plot(1:10,ones(1,10));
set(gca,'YColor','r')
  3 Comments
Derek Neal
Derek Neal on 4 Feb 2022
Edited: Derek Neal on 4 Feb 2022
Fantastic. Thank you Dave! Yes, I decided to use yyaxis.

Sign in to comment.

More Answers (0)

Categories

Find more on Two y-axis in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by