Plot legend has too many entries
6 次查看(过去 30 天)
显示 更早的评论
I am plotting a stress-strain curve for a steel sample and am trying to include the yield line (at 0.02%), show it's intersection with the curve and also the UTS. Thus I intend for four plotted datasets to be overlayed on the same plot. My script looks like the following:
clear
clc
x1 = 0.02 %creates a linear vector using a computed slope from the elastic region of the curve
y1 = 0
m = 13254.4807
x = linspace(0, 0.05, 1000)
y_steel=m*(x-x1)
tab1 = readtable("S2G2T5_1.csv"); %fe
tab2 = readtable("S2G2T5_2.csv"); %al
A_Steel = table2array((tab1(1,"Thickness_mm_")))*table2array((tab1(1,"GaugeWidth_mm_"))); %Area calculation for each sample
A_Alum = table2array((tab2(1,"Thickness_mm_")))*table2array((tab2(1,"GaugeWidth_mm_")));
L_Steel = 78.54; %Input from recorded data
L_Alum = 81.68;
Stress_Steel = table2array(tab1(:,"Force_kN_"))/A_Steel; %\sigma calculation for each sample
Stress_Alum = table2array(tab2(:,"Force_kN_"))/A_Alum;
SmoothStressSteel = smoothdata(Stress_Steel,1,"loess")*1000 %applies smoothing to the data
SmoothStressAlum = smoothdata(Stress_Alum,1,"loess")*1000
Strain_Steel = table2array(tab1(:,"Displacement_mm_"))/L_Steel %\epsilon calculation for each sample
Strain_Alum = table2array(tab2(:,"Displacement_mm_"))/L_Alum
figure(20)
Steel_plot2 = plot(Strain_Steel,SmoothStressSteel); %stress-strain curve
hold on
yieldline_steel = plot(x1,y1,x,y_steel) %yield line at 0.02% strain
yieldpoint_steel = plot(0.0462462,347.88,'diamond') %intersection point
annotation("textbox",[.27 .8 .3 .01],'String','\sigma_Y = 348.2 MPa','EdgeColor','w')
max(SmoothStressSteel) %determines the max value for UTS
UTS_steel = plot(.11,360.6078,'diamond') %ultimate tensile strength point
annotation("textbox",[.5 .9 .3 .01],'String','\sigma_U_T_S = 360.6 MPa','EdgeColor','w')
leg2 = legend(["Steel","Yield line (.02%)","\sigma_Y = 348.2 MPa","\sigma_U_T_S = 360.6 MPa"],'Location','southeast')
ylim([0,400])
hold off
print("Steel Stress-Strain.png",'-dpng','-f20') %prints figure to png
The following figure looks like this:
Based on the legend, there is some object occupying the data for the legend in the second spot (red) that does not exist in the plot. The only four datasets that I am plotting are:
1. Stress-strain curve for steel (seen in blue)
2. Yield line at 0.02% (seen in yellow)
3. Yield point of intersection (seen in purple)
4. Point of ultimate tensile strength (seen in green)
My first intuition is that there is something wrong with either the yield line (yellow) and it's associated calculation toward the beginning of the code or the plotted points of or .
However it could be something else and I am hoping someone with a better set of eyes can find a problem I have yet to identify.
1 个评论
Dyuman Joshi
2023-9-21
"The only four datasets that I am plotting are: "
You have plotted 5 data sets -
% #1
Steel_plot2 = plot(Strain_Steel,SmoothStressSteel); %stress-strain curve
% #2 and #3
yieldline_steel = plot(x1,y1,x,y_steel) %yield line at 0.02% strain
% #4
yieldpoint_steel = plot(0.0462462,347.88,'diamond') %intersection point
% #5
UTS_steel = plot(.11,360.6078,'diamond') %ultimate tensile strength point
采纳的回答
the cyclist
2023-9-21
This line
yieldline_steel = plot(x1,y1,x,y_steel)
plots two objects, the first of which is just a single point.
更多回答(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!