Name legend on graph with a second y axis
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Walter Roberson
2025 年 3 月 27 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

