plotting 2 y-axis in one graph
조회 수: 3 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Dyuman Joshi
2023년 10월 4일
The ylabel() call for the left y-axis should be done before changing the y-axis to right.
Refer to this example - https://in.mathworks.com/help/matlab/ref/yyaxis.html#bunqz6e-1
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!