Black axes for yyaxis (not default blue and orange)

조회 수: 1,204 (최근 30일)
Heidi Hirsh
Heidi Hirsh 2019년 3월 23일
댓글: DGM 2023년 9월 10일
I'm having a hard time making the two y axes in my yyaxis plot black instead of the default blue left axis and orange left axis. I think I need to call the axis handle for each but I'm not sure how to define them for multiple y axes.
figure
yyaxis left
plot(btimestamp(k1:k2),Bmean3637(k1:k2),'k');
ylabel('BEUTI')
ylim([-5 40])
yyaxis right
plot(btimestamp(k1:k2),t_mean(k1:k2),'g-');
hold on;
plot(btimestamp(k1:k2),b_mean(k1:k2),'b-');
ylabel('Mean Daily pH')
ylim([7.2 8.2])
legend('BEUTI','Upper pH','Lower pH')
datetick
set(AX,{'ycolor'},{'r';'b'})

채택된 답변

Star Strider
Star Strider 2019년 3월 23일
Try this:
figure
yyaxis left
plot((1:10), rand(1, 10), 'g')
yyaxis right
plot((5:15), sin((5:15)/5), 'r')
ax = gca;
ax.YAxis(1).Color = 'k';
ax.YAxis(2).Color = 'k';
Experiment to get the result you want.
  댓글 수: 4
Bin Jiang
Bin Jiang 2020년 4월 26일
or a simpler version
set(gca,'YColor','k');
Cheers,
Sara Fawal
Sara Fawal 2020년 7월 23일
Hello Star,
Is there a way to set ALL the Y axis colors in a subplot to black using the findall command?
I want to do this: set(findall(gcf, 'ALL Y Axis Colors', 'k'))
Can it be done.
Thank you

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Julian Dönges
Julian Dönges 2021년 8월 20일
It is also possible to define the color order beforehand, see yyaxis documentation:
colororder({'b','m'})
yyaxis left
y = [1 2; 3 4];
plot(y)
yyaxis right
z = [4 3; 2 1];
plot(z)
legend
To make both sides black, you would write the first line as
colororder({'k','k'})
  댓글 수: 4
Jingfeng
Jingfeng 2023년 9월 10일
"nextile" is what?
DGM
DGM 2023년 9월 10일
nexttile() creates axes in a tiledlayout. The output is a handle.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by