plotting 2 y-axis in one graph

3 views (last 30 days)
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

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 4 Oct 2023
The ylabel() call for the left y-axis should be done before changing the y-axis to right.

More Answers (0)

Categories

Find more on Graphics in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!