フィルターのクリア

plotting 2 y-axis in one graph

3 ビュー (過去 30 日間)
Ke Yeun Yong
Ke Yeun Yong 2023 年 10 月 4 日
回答済み: Dyuman Joshi 2023 年 10 月 4 日
Hi,
I am trying to plot 2 y-axis in 1 x-axis ( as shown as the picture), but my coding seems to have error in plotting it.
I want to plot (TAS, power available) x2 and (TAS, power required) x2
I also have error in labelling the y-axis.
U = TAS;
W = P_available_22K;
X = P_required_22K;
Y = P_available_26K;
Z = P_required_26K;
yyaxis left
% POWER AVAILABLE 22K VS TAS
plot(U([1:37]),W([1:37]), 'Color', 'r', 'Linestyle', '--', 'linewidth', 1.0);
hold on;
% POWER AVAILABLE 26K VS TAS
plot(U([1:42]),Y([1:42]), 'Color', 'b', 'Linestyle', '-', 'linewidth', 1.0);
yyaxis right
% POWER REQUIRED 22K VS TAS
plot(U([1:37]),X([1:37]), 'Color', 'r', 'Linestyle', '--', 'linewidth', 1.0);
hold on;
% POWER REQUIRED 26K VS TAS
plot(U([1:42]),Z([1:42]), 'Color', 'b', 'Linestyle', '-', 'linewidth', 1.0);
xlabel('TAS (m/s)','FontSize',14, 'fontweight', 'bold', 'color', '[0 0 1]')
ylabel('Power Available (W)', '','FontSize',14, 'fontweight', 'bold', 'color', '[0 0 1]')
ylabel('Power Required (W)', '','FontSize',14, 'fontweight', 'bold', 'color', '[0 0 1]')
title('Power Available Vs Power Required','FontSize',16, 'fontweight', 'bold', 'color', '#000000')
legend('Power Available 22K','Power Available 26K', 'Power required 22K','Power required 26K','Location','Bestoutside')
grid on
grid minor

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 10 月 4 日
The ylabel() call for the left y-axis should be done before changing the y-axis to right.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePlot Customization についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by