필터 지우기
필터 지우기

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 CenterFile Exchange에서 Plot Customization에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by