yyaxis関数使用時にy軸の色が変えられない

조회 수: 37 (최근 30일)
佳琳 杉浦
佳琳 杉浦 2022년 4월 14일
답변: Hernia Baby 2022년 4월 15일
yyaxis関数を用いて2軸グラフを作成したいのですが、y軸の色がどうしても変えられません。「.YColor」や「YAxis(1).Color」を使っても、2軸両方ともデフォルトの色(青と赤)のままでした。
解決方法を教えていただきたいです。
以下、コードです。
figure(11)
yyaxis left
plot(distance_h1,v_h1,'r','LineWidth',2)
ylabel('Velocity [m/s]','FontSize',30,'Interpreter','latex')
axis([0 1.5 0 0.5])
yyaxis right
plot(distance_h1,p_h1,'k','LineWidth',2)
ylabel('Pitch angle [$^\circ$]','FontSize',30,'Interpreter','latex')
axis([0 1.5 -3 3])
grid on
xlabel('Travelled distance [m]','FontSize',30,'Interpreter','latex') %各軸ラベルを斜体でかつ諸々設定する
legend('Velocity','Pitch angle', 'FontSize',10,'Interpreter','latex','Location','northwest')
axis_obj = gca; %軸の字体
axis_obj.YColor = 'k';
axis_obj.FontSize = 18; %軸目盛のフォントサイズ

답변 (1개)

Hernia Baby
Hernia Baby 2022년 4월 15일
axis_objがどのような値を持っているか確認してみてください
おそらく axis_ob j.YAxis(1).Color で対応可能かなと思っています
clc,clear,close all;
x = linspace(0,10);
y = sin(3*x);
yyaxis left
plot(x,y)
z = sin(3*x).*exp(0.5*x);
yyaxis right
plot(x,z)
ylim([-150 150])
ax = gca
ax =
Axes with properties: YAxisLocation: 'right' YAxis: [2×1 NumericRuler] YLim: [-150 150] XLim: [0 10] XScale: 'linear' YScale: 'linear' Position: [0.1300 0.1100 0.7750 0.8150] Units: 'normalized' Show all properties
YAxisが怪しそうです
ax.YAxis(1).Color = 'k'
ax =
Axes with properties: YAxisLocation: 'right' YAxis: [2×1 NumericRuler] YLim: [-150 150] XLim: [0 10] XScale: 'linear' YScale: 'linear' Position: [0.1300 0.1100 0.7750 0.8150] Units: 'normalized' Show all properties
ax.YAxis(2).Color = 'r'
ax =
Axes with properties: YAxisLocation: 'right' YAxis: [2×1 NumericRuler] YLim: [-150 150] XLim: [0 10] XScale: 'linear' YScale: 'linear' Position: [0.1300 0.1100 0.7750 0.8150] Units: 'normalized' Show all properties

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!