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

37 views (last 30 days)
佳琳 杉浦
佳琳 杉浦 on 14 Apr 2022
Answered: Hernia Baby on 15 Apr 2022
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; %軸目盛のフォントサイズ

Answers (1)

Hernia Baby
Hernia Baby on 15 Apr 2022
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

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!