plotting 2 y-axis in one graph
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ke Yeun Yong
el 4 de Oct. de 2023
Respondida: Dyuman Joshi
el 4 de Oct. de 2023
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 comentarios
Respuesta aceptada
Dyuman Joshi
el 4 de Oct. de 2023
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 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!