Plot legend has too many entries

6 vues (au cours des 30 derniers jours)
Andrew
Andrew le 21 Sep 2023
Commenté : Dyuman Joshi le 21 Sep 2023
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 commentaire
Dyuman Joshi
Dyuman Joshi le 21 Sep 2023
"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

Connectez-vous pour commenter.

Réponse acceptée

the cyclist
the cyclist le 21 Sep 2023
This line
yieldline_steel = plot(x1,y1,x,y_steel)
plots two objects, the first of which is just a single point.
  1 commentaire
Andrew
Andrew le 21 Sep 2023
Thank you, this was the issue.
Goes to show the dangers of copying code from the forums I suppose!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by