Name legend on graph with a second y axis
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Marol Valencia
le 27 Mar 2025
Commenté : Walter Roberson
le 28 Mar 2025
I am plotting three curves on the same figure, but I have not been able to name the third legend because the third curve is plotted against a second y axis. In the following code is the graph and the things I've tried
T_4340_ASM = [ 205
315
425
540
650]
S_u_4340_ASM = [ 1980
1760
1500
1240
1020]
S_y_4340_ASM = [ 1860
1620
1365
1160
860]
El_4340_ASM = [ 11
12
14
17
20]
HB_4340_ASM = [ 520
490
440
360
290]
figure(1)
plot(T_4340_ASM,S_y_4340_ASM,"Marker","square",Color=[0.6350 0.0780 0.1840])
hold on
plot(T_4340_ASM,S_u_4340_ASM,"Marker","pentagram","Color",[0 0.4470 0.7410])
hold on
title('Tempering temperature vs 4340 Steel Mechanical properties')
xlabel('Temperature[C°]')
ylabel('[MPa]')
legend('Yield Point','Tensile Strength') %If I put a third entry on here it ignores it because at this point the other curve is not plotted yet
yyaxis right
plot(T_4340_ASM,El_4340_ASM,"Marker","o") %And if i put it after here it just names the last legend
ylabel('Elongation [%]')
0 commentaires
Réponse acceptée
Walter Roberson
le 27 Mar 2025
T_4340_ASM = [ 205
315
425
540
650]
S_u_4340_ASM = [ 1980
1760
1500
1240
1020]
S_y_4340_ASM = [ 1860
1620
1365
1160
860]
El_4340_ASM = [ 11
12
14
17
20]
HB_4340_ASM = [ 520
490
440
360
290]
figure(1)
h(1) = plot(T_4340_ASM,S_y_4340_ASM,"Marker","square",Color=[0.6350 0.0780 0.1840]);
hold on
h(2) = plot(T_4340_ASM,S_u_4340_ASM,"Marker","pentagram","Color",[0 0.4470 0.7410]);
hold on
title('Tempering temperature vs 4340 Steel Mechanical properties')
xlabel('Temperature[C°]')
ylabel('[MPa]')
legend('Yield Point','Tensile Strength') %If I put a third entry on here it ignores it because at this point the other curve is not plotted yet
yyaxis right
h(3) = plot(T_4340_ASM,El_4340_ASM,"Marker","o"); %And if i put it after here it just names the last legend
ylabel('Elongation [%]')
legend(h, {'S_y_4340_ASM', 'S_u_4340_ASM', 'El_4340_ASM'})
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

