Plotting stress-strain curves is a useful skill in mechanical engineering because it allows us to derive mechanical properties of materials such as tensile strength, elastic modulus, yield strength and ductility. Plotting stress strain curves can be accomplished with Excel and MATLAB, but what about plotting stress strain curves with Python? Follow along to find out.

We will use Python, matplotlib, pandas, holoviews and scipy to build the bar plot. I recommend undergraduate engineers use the Anaconda distribution of Python, which comes with matplotlib, pandas, and scipy already installed. For help installing Anaconda, see a previous blog post: Installing Anaconda on Windows 10. If matplotlib, pandas, holoviews, and scipy are not available in your version of Python, open a terminal or the Anaconda Prompt and type:

$ pip install matplotlib
$ pip install pandas
$ pip install holoviews
$ pip install scipy

or

> conda install matplotlib
> conda install pandas
> conda install holoviews
> conda install scipy

The data we are going to plot is stored in two Microsoft Excel Files. You can download the sample data here (clicking the link will start the download):

Al_6061.xls

We'll use pandas to load the data into the notebook.

Note that when I first tried to run the pd.read_excel() function, I was returned an error:

ImportError: Install xlrd >= 0.9.0 for Excel support

To solve this, I went to the Anaconda Prompt and typed:

> conda install xlrd

Once the xlrd module was installed, the pd.read_excel() function worked just fine.

To start the Jupyter notebook, we need to import the required packages:

pandas numpy matplotlib scipy

The %matplotlib inline magic command is add so that we can see our plots right in the jupyter notebook.


In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import linregress
%matplotlib inline

In [2]:
dfa=pd.read_excel('Al_6061.xls')
pd.options.display.max_rows = 999
dfa


Out[2]:
TESTNUM POINTNUM TIME POSIT FORCE EXT CH5 CH6 CH7 CH8
0 703 1 7.373 0.07306 201.788025 0.277029 -52.170364 NaN NaN NaN
1 703 2 7.581 0.07382 210.158737 0.000466 -52.167755 NaN NaN NaN
2 703 3 8.778 0.07826 260.129089 0.002002 -52.165543 NaN NaN NaN
3 703 4 9.879 0.08290 313.650208 0.003473 -52.167255 NaN NaN NaN
4 703 5 10.778 0.08672 366.283081 0.006554 -52.166386 NaN NaN NaN
5 703 6 11.479 0.08946 418.915558 0.009250 -52.165379 NaN NaN NaN
6 703 7 11.882 0.09138 483.722656 0.011572 -52.167137 NaN NaN NaN
7 703 8 12.378 0.09332 534.705505 0.014460 -52.167999 NaN NaN NaN
8 703 9 12.875 0.09562 595.326294 0.017394 -52.171307 NaN NaN NaN
9 703 10 13.375 0.09756 647.195984 0.019679 -52.169579 NaN NaN NaN
10 703 11 13.876 0.09948 700.460266 0.022321 -52.173042 NaN NaN NaN
11 703 12 14.279 0.10142 754.992249 0.024551 -52.176601 NaN NaN NaN
12 703 13 14.781 0.10332 813.328308 0.026809 -52.172192 NaN NaN NaN
13 703 14 15.281 0.10526 862.533081 0.029359 -52.177788 NaN NaN NaN
14 703 15 15.778 0.10758 919.092773 0.031644 -52.171539 NaN NaN NaN
15 703 16 16.376 0.10990 976.920044 0.034176 -52.171696 NaN NaN NaN
16 703 17 16.876 0.11220 1031.322998 0.037019 -52.175457 NaN NaN NaN
17 703 18 17.375 0.11414 1081.667358 0.039414 -52.176987 NaN NaN NaN
18 703 19 17.875 0.11608 1141.141724 0.042165 -52.180363 NaN NaN NaN
19 703 20 18.177 0.11756 1191.865723 0.044624 -52.176327 NaN NaN NaN
20 703 21 18.679 0.11950 1254.002075 0.047558 -52.173019 NaN NaN NaN
21 703 22 19.076 0.12102 1304.218018 0.050035 -52.175175 NaN NaN NaN
22 703 23 19.375 0.12256 1355.321045 0.052868 -52.171856 NaN NaN NaN
23 703 24 19.781 0.12410 1411.622803 0.055547 -52.171715 NaN NaN NaN
24 703 25 20.179 0.12560 1465.134399 0.058152 -52.169346 NaN NaN NaN
25 703 26 20.581 0.12752 1530.184570 0.061278 -52.172066 NaN NaN NaN
26 703 27 20.976 0.12908 1584.963135 0.064066 -52.171345 NaN NaN NaN
27 703 28 21.380 0.13064 1640.375366 0.066762 -52.168720 NaN NaN NaN
28 703 29 21.780 0.13214 1696.420898 0.069449 -52.168377 NaN NaN NaN
29 703 30 22.078 0.13370 1753.607300 0.072082 -52.168316 NaN NaN NaN
30 703 31 22.476 0.13526 1809.398438 0.074934 -52.166210 NaN NaN NaN
31 703 32 22.875 0.13678 1865.189087 0.077831 -52.166470 NaN NaN NaN
32 703 33 23.278 0.13872 1937.716064 0.081487 -52.161282 NaN NaN NaN
33 703 34 23.677 0.14024 1994.646729 0.084467 -52.161545 NaN NaN NaN
34 703 35 24.079 0.14178 2053.098389 0.087191 -52.162415 NaN NaN NaN
35 703 36 24.480 0.14334 2110.281494 0.090180 -52.158974 NaN NaN NaN
36 703 37 24.780 0.14486 2171.394775 0.093123 -52.157627 NaN NaN NaN
37 703 38 25.177 0.14640 2232.126953 0.096149 -52.155125 NaN NaN NaN
38 703 39 25.577 0.14796 2293.746094 0.099101 -52.155869 NaN NaN NaN
39 703 40 25.877 0.14948 2353.336182 0.102117 -52.152748 NaN NaN NaN
40 703 41 26.176 0.15064 2403.416748 0.104348 -52.150948 NaN NaN NaN
41 703 42 26.582 0.15220 2467.062744 0.107821 -52.150326 NaN NaN NaN
42 703 43 26.978 0.15368 2525.510010 0.110636 -52.147751 NaN NaN NaN
43 703 44 27.278 0.15522 2592.324707 0.113817 -52.146225 NaN NaN NaN
44 703 45 27.675 0.15672 2654.701172 0.116843 -52.145241 NaN NaN NaN
45 703 46 27.976 0.15784 2704.906006 0.119237 -52.144218 NaN NaN NaN
46 703 47 28.376 0.15974 2786.171387 0.123177 -52.141960 NaN NaN NaN
47 703 48 28.678 0.16088 2835.361084 0.125700 -52.142113 NaN NaN NaN
48 703 49 28.981 0.16202 2887.339355 0.128213 -52.141045 NaN NaN NaN
49 703 50 29.281 0.16318 2936.781982 0.130846 -52.138977 NaN NaN NaN
50 703 51 29.581 0.16470 3009.170166 0.134502 -52.135349 NaN NaN NaN
51 703 52 29.878 0.16588 3061.147217 0.136988 -52.137321 NaN NaN NaN
52 703 53 30.180 0.16702 3115.532471 0.139685 -52.138752 NaN NaN NaN
53 703 54 30.478 0.16820 3169.410156 0.142354 -52.135128 NaN NaN NaN
54 703 55 30.776 0.16936 3225.569580 0.145251 -52.133839 NaN NaN NaN
55 703 56 30.980 0.17054 3280.713867 0.148167 -52.129978 NaN NaN NaN
56 703 57 31.280 0.17168 3335.477783 0.150918 -52.131199 NaN NaN NaN
57 703 58 31.579 0.17284 3391.001465 0.153834 -52.127872 NaN NaN NaN
58 703 59 31.875 0.17398 3445.891113 0.156960 -52.125137 NaN NaN NaN
59 703 60 32.176 0.17514 3505.090088 0.159702 -52.128220 NaN NaN NaN
60 703 61 32.379 0.17628 3562.260498 0.162783 -52.126144 NaN NaN NaN
61 703 62 32.677 0.17744 3618.289307 0.165964 -52.125992 NaN NaN NaN
62 703 63 32.980 0.17860 3677.613525 0.169135 -52.121746 NaN NaN NaN
63 703 64 33.280 0.17976 3736.050049 0.172152 -52.124775 NaN NaN NaN
64 703 65 33.578 0.18092 3796.133545 0.175141 -52.120155 NaN NaN NaN
65 703 66 33.780 0.18204 3853.174561 0.178184 -52.120155 NaN NaN NaN
66 703 67 34.082 0.18318 3912.750488 0.181146 -52.118755 NaN NaN NaN
67 703 68 34.380 0.18432 3972.325439 0.184135 -52.116673 NaN NaN NaN
68 703 69 34.675 0.18550 4030.632324 0.187124 -52.119858 NaN NaN NaN
69 703 70 34.981 0.18704 4114.542480 0.191347 -52.115105 NaN NaN NaN
70 703 71 35.281 0.18820 4174.369629 0.194464 -52.112717 NaN NaN NaN
71 703 72 35.583 0.18936 4238.251465 0.197809 -52.112133 NaN NaN NaN
72 703 73 35.885 0.19052 4297.062988 0.201008 -52.110844 NaN NaN NaN
73 703 74 36.177 0.19168 4361.450684 0.204116 -52.110695 NaN NaN NaN
74 703 75 36.379 0.19286 4424.443848 0.207425 -52.108162 NaN NaN NaN
75 703 76 36.676 0.19402 4487.309570 0.210788 -52.108795 NaN NaN NaN
76 703 77 36.981 0.19516 4549.921387 0.213942 -52.105953 NaN NaN NaN
77 703 78 37.276 0.19632 4613.039551 0.217251 -52.105175 NaN NaN NaN
78 703 79 37.579 0.19786 4698.969727 0.221858 -52.101742 NaN NaN NaN
79 703 80 37.878 0.19906 4764.240723 0.225377 -52.102356 NaN NaN NaN
80 703 81 38.179 0.20018 4829.257812 0.228923 -52.102299 NaN NaN NaN
81 703 82 38.477 0.20138 4896.175293 0.232424 -52.098377 NaN NaN NaN
82 703 83 38.779 0.20252 4961.570801 0.236089 -52.094353 NaN NaN NaN
83 703 84 39.076 0.20408 5047.116699 0.240586 -52.097595 NaN NaN NaN
84 703 85 39.379 0.20522 5114.284668 0.244160 -52.097755 NaN NaN NaN
85 703 86 39.678 0.20634 5181.199219 0.247771 -52.093220 NaN NaN NaN
86 703 87 39.980 0.20754 5247.605957 0.251409 -52.093452 NaN NaN NaN
87 703 88 40.176 0.20868 5313.251953 0.255019 -52.093452 NaN NaN NaN
88 703 89 40.378 0.20946 5364.323242 0.257624 -52.094067 NaN NaN NaN
89 703 90 40.675 0.21064 5432.249023 0.261308 -52.092701 NaN NaN NaN
90 703 91 40.977 0.21178 5500.300293 0.265074 -52.092709 NaN NaN NaN
91 703 92 41.279 0.21296 5568.604492 0.268931 -52.093082 NaN NaN NaN
92 703 93 41.578 0.21452 5662.759766 0.274168 -52.089302 NaN NaN NaN
93 703 94 41.880 0.21570 5729.921875 0.277916 -52.089561 NaN NaN NaN
94 703 95 42.177 0.21682 5798.983887 0.281782 -52.090157 NaN NaN NaN
95 703 96 42.377 0.21760 5849.417480 0.284369 -52.086918 NaN NaN NaN
96 703 97 42.677 0.21878 5918.478516 0.288336 -52.082230 NaN NaN NaN
97 703 98 42.881 0.21992 5991.086914 0.292139 -52.082230 NaN NaN NaN
98 703 99 43.178 0.22104 6062.046387 0.296078 -52.080555 NaN NaN NaN
99 703 100 43.380 0.22188 6112.605469 0.298848 -52.080555 NaN NaN NaN
100 703 101 43.682 0.22300 6185.591309 0.302815 -52.077736 NaN NaN NaN
101 703 102 43.980 0.22414 6259.083496 0.307001 -52.078724 NaN NaN NaN
102 703 103 44.176 0.22496 6308.246582 0.309560 -52.078724 NaN NaN NaN
103 703 104 44.376 0.22610 6381.104004 0.313564 -52.078117 NaN NaN NaN
104 703 105 44.576 0.22686 6430.393066 0.316352 -52.076061 NaN NaN NaN
105 703 106 44.777 0.22764 6480.188477 0.318957 -52.071659 NaN NaN NaN
106 703 107 44.976 0.22842 6532.137695 0.321799 -52.071659 NaN NaN NaN
107 703 108 45.284 0.22956 6605.499023 0.325766 -52.071148 NaN NaN NaN
108 703 109 45.481 0.23032 6656.813477 0.328573 -52.071148 NaN NaN NaN
109 703 110 45.578 0.23114 6708.127441 0.331397 -52.066525 NaN NaN NaN
110 703 111 45.877 0.23228 6781.486816 0.335702 -52.065323 NaN NaN NaN
111 703 112 46.077 0.23304 6833.053711 0.338517 -52.065323 NaN NaN NaN
112 703 113 46.281 0.23382 6885.506836 0.341241 -52.062733 NaN NaN NaN
113 703 114 46.477 0.23462 6935.678223 0.344029 -52.061634 NaN NaN NaN
114 703 115 46.678 0.23538 6988.257812 0.346808 -52.061687 NaN NaN NaN
115 703 116 46.879 0.23652 7066.934570 0.351177 -52.061687 NaN NaN NaN
116 703 117 47.083 0.23730 7119.639160 0.354175 -52.056622 NaN NaN NaN
117 703 118 47.378 0.23848 7196.794922 0.358352 -52.056705 NaN NaN NaN
118 703 119 47.581 0.23926 7249.751465 0.361085 -52.056152 NaN NaN NaN
119 703 120 47.776 0.24004 7305.241699 0.364165 -52.052395 NaN NaN NaN
120 703 121 47.981 0.24078 7358.450684 0.366935 -52.052326 NaN NaN NaN
121 703 122 48.181 0.24200 7438.644043 0.371423 -52.052326 NaN NaN NaN
122 703 123 48.376 0.24272 7492.485352 0.374174 -52.052410 NaN NaN NaN
123 703 124 48.576 0.24348 7544.299805 0.377447 -52.048862 NaN NaN NaN
124 703 125 48.780 0.24428 7604.094727 0.380500 -52.047176 NaN NaN NaN
125 703 126 49.076 0.24542 7684.157715 0.384805 -52.046890 NaN NaN NaN
126 703 127 49.280 0.24620 7737.110840 0.387547 -52.046890 NaN NaN NaN
127 703 128 49.476 0.24734 7823.632812 0.392126 -52.045189 NaN NaN NaN
128 703 129 49.681 0.24814 7875.571289 0.395170 -52.038990 NaN NaN NaN
129 703 130 49.876 0.24892 7929.789551 0.398168 -52.039272 NaN NaN NaN
130 703 131 50.079 0.24968 7986.793457 0.401312 -52.039272 NaN NaN NaN
131 703 132 50.280 0.25042 8039.364258 0.404530 -52.036835 NaN NaN NaN
132 703 133 50.479 0.25122 8098.647949 0.407994 -52.034389 NaN NaN NaN
133 703 134 50.776 0.25240 8178.451660 0.413049 -52.033585 NaN NaN NaN
134 703 135 50.880 0.25318 8229.120117 0.416312 -52.033585 NaN NaN NaN
135 703 136 51.078 0.25408 8011.495605 0.405033 -52.025146 NaN NaN NaN
136 703 137 51.278 0.25480 8100.167969 0.409255 -52.033924 NaN NaN NaN
137 703 138 51.378 0.25518 8155.017090 0.411842 -52.033924 NaN NaN NaN
138 703 139 51.579 0.25584 8245.713867 0.416568 -52.030361 NaN NaN NaN
139 703 140 51.778 0.25660 8323.996094 0.420453 -52.026833 NaN NaN NaN
140 703 141 51.976 0.25742 8388.090820 0.424365 -52.027321 NaN NaN NaN
141 703 142 52.080 0.25820 8444.330078 0.428231 -52.027321 NaN NaN NaN
142 703 143 52.279 0.25900 8503.230469 0.432710 -52.020931 NaN NaN NaN
143 703 144 52.481 0.25972 8557.316406 0.437052 -52.020931 NaN NaN NaN
144 703 145 52.675 0.26048 8612.541992 0.441759 -52.016975 NaN NaN NaN
145 703 146 52.880 0.26130 8666.120117 0.446722 -52.014305 NaN NaN NaN
146 703 147 53.077 0.26206 8720.711914 0.451622 -52.013355 NaN NaN NaN
147 703 148 53.280 0.26322 8798.608398 0.459208 -52.013355 NaN NaN NaN
148 703 149 53.480 0.26398 8848.764648 0.464674 -52.009212 NaN NaN NaN
149 703 150 53.676 0.26478 8898.415039 0.470168 -52.001900 NaN NaN NaN
150 703 151 53.976 0.26594 8973.902344 0.479079 -52.005173 NaN NaN NaN
151 703 152 54.279 0.26706 9043.563477 0.488604 -52.000340 NaN NaN NaN
152 703 153 54.580 0.26828 9109.930664 0.499618 -51.991207 NaN NaN NaN
153 703 154 54.876 0.26978 9178.323242 0.518329 -51.988976 NaN NaN NaN
154 703 155 55.378 0.27174 9234.303711 0.555869 -51.976044 NaN NaN NaN
155 703 156 56.077 0.27484 9286.356445 0.638078 -51.934921 NaN NaN NaN
156 703 157 57.082 0.27870 9337.396484 0.756209 -51.874413 NaN NaN NaN
157 703 158 58.177 0.28336 9377.670898 0.907512 -51.799210 NaN NaN NaN
158 703 159 59.280 0.28794 9407.939453 1.064463 -51.722092 NaN NaN NaN
159 703 160 60.277 0.29222 9432.002930 1.211423 -51.650108 NaN NaN NaN
160 703 161 61.281 0.29646 9455.559570 1.360477 -51.598339 NaN NaN NaN
161 703 162 62.378 0.30074 9478.735352 1.511349 -51.508747 NaN NaN NaN
162 703 163 63.380 0.30496 9497.479492 1.661628 -51.453686 NaN NaN NaN
163 703 164 64.380 0.30922 9517.995117 1.809311 -51.378418 NaN NaN NaN
164 703 165 65.378 0.31342 9538.259766 1.956911 -51.302135 NaN NaN NaN
165 703 166 66.478 0.31810 9559.916016 2.117107 -51.227318 NaN NaN NaN
166 703 167 67.583 0.32232 9579.925781 2.264277 -51.154648 NaN NaN NaN
167 703 168 68.679 0.32696 9598.415039 2.422947 -51.076405 NaN NaN NaN
168 703 169 69.776 0.33162 9618.678711 2.581068 -51.010696 NaN NaN NaN
169 703 170 70.877 0.33620 9639.321289 2.739079 -50.942047 NaN NaN NaN
170 703 171 71.981 0.34086 9659.331055 2.897685 -50.857197 NaN NaN NaN
171 703 172 72.680 0.34394 9671.362305 3.003093 -50.821419 NaN NaN NaN
172 703 173 89.980 0.34654 9331.823242 3.003093 -50.746449 NaN NaN NaN
173 703 174 90.277 0.34694 9401.987305 3.003093 -50.746758 NaN NaN NaN
174 703 175 90.378 0.34732 9481.268555 3.003093 -50.740696 NaN NaN NaN
175 703 176 90.477 0.34774 9574.226562 3.003093 -50.740696 NaN NaN NaN
176 703 177 90.575 0.34826 9673.767578 3.003093 -50.740696 NaN NaN NaN
177 703 178 90.686 0.34886 9754.059570 3.003093 -50.734818 NaN NaN NaN
178 703 179 90.778 0.34948 9808.514648 3.003093 -50.734818 NaN NaN NaN
179 703 180 95.776 0.39088 9858.791016 3.003093 -50.068653 NaN NaN NaN
180 703 181 97.778 0.40710 9908.432617 3.003093 -49.812840 NaN NaN NaN
181 703 182 100.181 0.42720 9958.328125 3.003093 -49.495842 NaN NaN NaN
182 703 183 103.478 0.45502 10009.362305 3.003093 -49.013668 NaN NaN NaN
183 703 184 107.680 0.48980 10039.375000 3.003093 -48.419338 NaN NaN NaN
184 703 185 112.577 0.53078 9989.987305 3.003093 -47.598503 NaN NaN NaN
185 703 186 113.980 0.54236 9938.066406 3.003093 -47.346455 NaN NaN NaN
186 703 187 114.975 0.55088 9880.446289 3.003093 -47.147011 NaN NaN NaN
187 703 188 115.778 0.55704 9830.549805 3.003093 -46.988422 NaN NaN NaN
188 703 189 116.380 0.56244 9778.120117 3.003093 -46.882923 NaN NaN NaN
189 703 190 117.076 0.56788 9724.171875 3.003093 -46.728683 NaN NaN NaN
190 703 191 117.576 0.57254 9674.401367 3.003093 -46.623890 NaN NaN NaN
191 703 192 118.180 0.57718 9617.665039 3.003093 -46.519733 NaN NaN NaN
192 703 193 118.774 0.58178 9559.029297 3.003093 -46.414204 NaN NaN NaN
193 703 194 119.277 0.58644 9498.492188 3.003093 -46.305241 NaN NaN NaN
194 703 195 119.776 0.59030 9447.707031 3.003093 -46.196098 NaN NaN NaN
195 703 196 120.179 0.59416 9389.702148 3.003093 -46.142693 NaN NaN NaN
196 703 197 120.681 0.59804 9336.509766 3.003093 -46.031967 NaN NaN NaN
197 703 198 121.178 0.60190 9278.630859 3.003093 -45.921314 NaN NaN NaN
198 703 199 121.579 0.60576 9217.458008 3.003093 -45.810070 NaN NaN NaN
199 703 200 122.076 0.60962 9156.159180 3.003093 -45.754959 NaN NaN NaN
200 703 201 122.576 0.61350 9097.138672 3.003093 -45.651554 NaN NaN NaN
201 703 202 122.877 0.61660 9045.843750 3.003093 -45.596348 NaN NaN NaN
202 703 203 123.275 0.61968 8990.622070 3.003093 -45.485043 NaN NaN NaN
203 703 204 123.679 0.62276 8939.325195 3.003093 -45.430489 NaN NaN NaN
204 703 205 124.079 0.62664 8869.916992 3.003093 -45.319424 NaN NaN NaN
205 703 206 124.476 0.62974 8815.833984 3.003093 -45.267330 NaN NaN NaN
206 703 207 124.878 0.63280 8761.117188 3.003093 -45.155403 NaN NaN NaN
207 703 208 125.180 0.63590 8703.739258 3.003093 -45.102959 NaN NaN NaN
208 703 209 125.579 0.63898 8646.741211 3.003093 -44.992519 NaN NaN NaN
209 703 210 125.977 0.64210 8583.663086 3.003093 -44.933586 NaN NaN NaN
210 703 211 126.379 0.64518 8526.663086 3.003093 -44.827873 NaN NaN NaN
211 703 212 126.676 0.64826 8464.343750 3.003093 -44.773857 NaN NaN NaN
212 703 213 127.077 0.65138 8397.589844 3.003093 -44.715385 NaN NaN NaN
213 703 214 127.480 0.65446 8338.056641 3.003093 -44.604507 NaN NaN NaN
214 703 215 127.880 0.65830 8256.861328 3.003093 -44.546909 NaN NaN NaN
215 703 216 128.178 0.66062 8206.192383 3.003093 -44.494556 NaN NaN NaN
216 703 217 128.483 0.66296 8155.396973 3.003093 -44.382210 NaN NaN NaN
217 703 218 128.777 0.66528 8104.094727 3.003093 -44.325550 NaN NaN NaN
218 703 219 129.176 0.66836 8036.070312 3.003093 -44.268997 NaN NaN NaN
219 703 220 129.380 0.67068 7985.527344 3.003093 -44.215889 NaN NaN NaN
220 703 221 129.677 0.67302 7930.422852 3.003093 -44.162060 NaN NaN NaN
221 703 222 129.977 0.67532 7877.725098 3.003093 -44.101597 NaN NaN NaN
222 703 223 130.279 0.67764 7825.786621 3.003093 -44.051384 NaN NaN NaN
223 703 224 130.476 0.67996 7766.627441 3.003093 -43.997040 NaN NaN NaN
224 703 225 130.778 0.68226 7711.141113 3.003093 -43.941296 NaN NaN NaN
225 703 226 131.080 0.68460 7653.880859 3.003093 -43.880756 NaN NaN NaN
226 703 227 131.380 0.68692 7598.014160 3.003093 -43.821201 NaN NaN NaN
227 703 228 131.680 0.68924 7537.712402 3.003093 -43.770218 NaN NaN NaN
228 703 229 131.878 0.69154 7478.296875 3.003093 -43.713715 NaN NaN NaN
229 703 230 132.177 0.69384 7416.094238 3.003093 -43.654919 NaN NaN NaN
230 703 231 132.479 0.69618 7352.496582 3.003093 -43.604691 NaN NaN NaN
231 703 232 132.779 0.69850 7286.491699 3.003093 -43.486691 NaN NaN NaN
232 703 233 132.979 0.70082 7219.219238 3.003093 -43.486691 NaN NaN NaN
233 703 234 133.178 0.70236 7169.176270 3.003093 -43.428616 NaN NaN NaN
234 703 235 133.178 0.70236 7169.176270 3.003093 -43.428616 NaN NaN NaN

We have a couple columns in our pandas dataframe. The columns of interest are FORCE and EXT. The FORCE column conntians the force values in units of pounds (lb). The EXT column contains the extension or strain in units of %. So line 215 of our dataframe shows a force = 8206.19283 lb and an extension or strain of 3.003093% which is the same as a strain of 0.03003093 in/in (unitless strain rather than % strain).

To convert the FORCE column to stress $\sigma$, we need to divide the force $F$ (in lb) by the cross-sectional area $A_0$ of the sample.

$$ \sigma = \frac{F}{A_0} $$

The cross-sectional area of the sample $A_0$ is the $\pi r^2$. Since we measured the diameter of the sample, and diamter $d$ is equal to two times the radius $r$

$$ A_0 = \pi (\frac{d}{2})^2 $$

In our case diamter $d = 0.506 \ in$


In [3]:
d = 0.506 #units: in
A0 = np.pi*(d/2)**2  #units: in^2
stress_Al = dfa['FORCE'][1:172]*(1/A0)*(0.001)
strain_Al = dfa['EXT'][1:172]*0.01

l0 = 2.0 #units: in
lf = 2.24 #units: in
strain_Al_f = (lf-l0)/l0 #units: in/in

In [4]:
plt.plot(strain_Al, stress_Al)
plt.show()


To zoom in on the elastic region, we'll do something a little fancy, we'll spin up a bokeh plot using holoviews.


In [5]:
import holoviews as hv
hv.extension('bokeh')
import bokeh



In [6]:
hv.Curve((strain_Al, stress_Al),'strain (in/in)','stress (ksi)')


Out[6]:

From this plot of force vs. extension, we can zoom into the linear region. It looks like the linear elastic region is from 1.5 ksi to 39.5 ksi. Pandas has this nice little method .between(). We can set lower and upper limits from the stress series and then use this to index out of both the stress and the strain series in the linear elastic region.


In [7]:
E_stress = stress_Al[stress_Al.between(1.5,39.5)]
E_strain = strain_Al[stress_Al.between(1.5,39.5)]
E_strain


Out[7]:
3      0.000035
4      0.000066
5      0.000093
6      0.000116
7      0.000145
8      0.000174
9      0.000197
10     0.000223
11     0.000246
12     0.000268
13     0.000294
14     0.000316
15     0.000342
16     0.000370
17     0.000394
18     0.000422
19     0.000446
20     0.000476
21     0.000500
22     0.000529
23     0.000555
24     0.000582
25     0.000613
26     0.000641
27     0.000668
28     0.000694
29     0.000721
30     0.000749
31     0.000778
32     0.000815
33     0.000845
34     0.000872
35     0.000902
36     0.000931
37     0.000961
38     0.000991
39     0.001021
40     0.001043
41     0.001078
42     0.001106
43     0.001138
44     0.001168
45     0.001192
46     0.001232
47     0.001257
48     0.001282
49     0.001308
50     0.001345
51     0.001370
52     0.001397
53     0.001424
54     0.001453
55     0.001482
56     0.001509
57     0.001538
58     0.001570
59     0.001597
60     0.001628
61     0.001660
62     0.001691
63     0.001722
64     0.001751
65     0.001782
66     0.001811
67     0.001841
68     0.001871
69     0.001913
70     0.001945
71     0.001978
72     0.002010
73     0.002041
74     0.002074
75     0.002108
76     0.002139
77     0.002173
78     0.002219
79     0.002254
80     0.002289
81     0.002324
82     0.002361
83     0.002406
84     0.002442
85     0.002478
86     0.002514
87     0.002550
88     0.002576
89     0.002613
90     0.002651
91     0.002689
92     0.002742
93     0.002779
94     0.002818
95     0.002844
96     0.002883
97     0.002921
98     0.002961
99     0.002988
100    0.003028
101    0.003070
102    0.003096
103    0.003136
104    0.003164
105    0.003190
106    0.003218
107    0.003258
108    0.003286
109    0.003314
110    0.003357
111    0.003385
112    0.003412
113    0.003440
114    0.003468
115    0.003512
116    0.003542
117    0.003584
118    0.003611
119    0.003642
120    0.003669
121    0.003714
122    0.003742
123    0.003774
124    0.003805
125    0.003848
126    0.003875
127    0.003921
128    0.003952
129    0.003982
Name: EXT, dtype: float64

Now we'll use scipy's linear regression function called linregress() to calculate the slope in the linear elastic region.


In [8]:
res = linregress(E_strain, E_stress)
res


Out[8]:
LinregressResult(slope=9554.613114858443, intercept=1.8422409352006461, rvalue=0.9996858660482589, pvalue=5.401839678530501e-202, stderr=21.4255942038523)

We see the slope = 9554.61 ksi. The rvalue = 0.999685 is very close to 1, so the linear elastic region is in fact pretty linear, not perfectly linear, but pretty close. Let's make a new variable E_Al for the elastic modulus of Aluminum


In [9]:
E_Al = res[0]
E_Al


Out[9]:
9554.613114858443

Now we will add a 0.002 or 0.2 % offset line to our plot. We will create a new linear series using the general form:

$$ y = mx + b $$

$y$ will be the $\sigma$ value, $x$ will be the offset strain values ($\epsilon - 0.002$), $m$ (the slope) is the elastic modulus $E$, and $b$ is the y-intercept. Adapting $y = mx + b$ to our 0.002 off-set line looks like the equation below.

$$ \sigma_{offset} = E (\epsilon - 0.002) + 0 $$

We can code $\sigma_{offset}$ line into a new series based on the equation above.


In [11]:
stress_offset = E_Al*(strain_Al - 0.002)

Now that the stress_offset series is defined, we can add our stress_offset line to the plot. When we call the plt.plot() command, we will pass in two x-y pairs. The first x-y pair is strain_Al, stress_Al, the second x-y pair is strain_Al, stress_offset.


In [12]:
plt.plot(strain_Al, stress_Al, strain_Al, stress_offset)
plt.show()


We can use holoviews again to zoom into the intersection point of the stress-strain curve (the blue line) and the 0.002 offset line (the orange line)


In [13]:
curve = hv.Curve((strain_Al, stress_Al),'strain (in/in)','stress (ksi)')
offset_curve = hv.Curve((strain_Al, stress_offset),'strain (in/in)','stress (ksi)')
curve * offset_curve


Out[13]:

If we use the zoom box (the zoom box button looks like a magnifying glass), we can clearly see the two lines cross at $\sigma_y = 46.28 \ ksi$. This compares well to a published value of around 40 ksi.

Let's define a variable to store yield strength.


In [57]:
sigma_y = 46.28

But what if we want to find this programatically, rather than by zooming into a plotted curve? Let's look at the points (without a line betweeen points) with holoviews. Instead of using the hv.Curve() method that makes line plots, we will use the hv.Scatter() method which builds a scatter plot of points.


In [15]:
scatter = hv.Scatter((strain_Al, stress_Al),'strain (in/in)','stress (ksi)')
offset_scatter = hv.Scatter((strain_Al, stress_offset),'strain (in/in)','stress (ksi)')
scatter * offset_scatter


Out[15]:

We need to find the two points on the blue stress strain curve where the crossover happens, and we need to find the the two red offset curve points where the crossover happens. Then we can do a little algebra and find the crossover point.


In [49]:
for i in range(2, len(strain_Al)):
    #when the offset line is first goes above the stress strain curve...
    if stress_offset[i] > stress_Al[i]:
        # pull out the points from the stress strain curve
        sx1 = strain_Al[i-1]
        sy1 = stress_Al[i-1]
        sy2 = stress_Al[i]
        sx2 = strain_Al[i]
        # pull out the points from the 0.002 offset line
        ox1 = strain_Al[i-1]
        oy1 = stress_offset[i-1]
        ox2 = strain_Al[i]
        oy2 = stress_offset[i]
        break

print(ox1)
print(oy1)
print(ox2)
print(oy2)     
print(sx1)
print(sy1)
print(sx2)
print(sy2)


0.00638077974319458
46.180053791959466
0.007562094330787659
46.4338704275076
0.00638077974319458
41.856655587633135
0.007562094330787659
53.14365943902356

In [84]:
# first set of two points, from the 0.002 offset line
x1 = ox1
y1 = oy1
x2 = ox2
y2 = oy2

# second set of two points, from the stress strain curve
x3 = sx1
y3 = sy1
x4 = sx2
y4 = sy2
# formula for the y corrdinate of the intersection two lines defined by two points
YS = ( (x1*y2-y1*x2)*(y3-y4) - (y1-y2)*(x3*y4-y3*x4)  ) / ( ( (x1-x2) * (y3-y4) ) - ( (y1-y2)*(x3-x4) ))

In [85]:
YS


Out[85]:
46.279512848068045

So our yield strength is 46.279. Rounded to four sig figs, this is the same value we found for $\sigma_y$ when we zoomed into the intersection point on the plot.

We can round the value of Py to three sig figs and print it out using an f-string.


In [86]:
print(f'the yield strength of the aluminum is {round(Py,1)} ksi')


the yield strength of the aluminum is 46.3 ksi

Tensile Strength

We can calculate the tensile strength of the aluminum by finding the maximum amount of stress on the stress strain curve.


In [87]:
TS = max(stress_Al)

We can print out the tensile strength to three sig figs using an f-string


In [88]:
print(f'the tensile strength of the aluminum is {round(TS,1)} ksi')


the tensile strength of the aluminum is 48.1 ksi

Ductility

We can calculate the ductility of the aluminum by taking the last point on the stress strain curve and drawing a line straight down to the x-axis parallel to the elastic modulus. We can find the final point on the stress strain curve using indexing.


In [89]:
xf = strain_Al[len(strain_Al)]
yf = stress_Al[len(strain_Al)]

Now using the point-slope formula for a line, we can determine where this line intecects the strain axis (the x-axis). The point-slope formula of a line is below.

$$ y - y_1 = m(x-x_1) $$

Since we want to find the x-intercept, we set y = 0.

$$ 0 - y_1 = m(x-x_1) $$

If we solve the equation above for x, we are left with

$$ x = x_1 - \frac{y_1}{m} $$

Our known points $x_1$ and $y_1$ are the last strain and stress values, and the slope $m$ is the elastic modulus $E$. The $x$ value that we solve for is equal to the ductility ($\%EL$).

$$ \%EL = \epsilon_{last} - \frac{ \sigma_{last}}{E} $$

We can code this with the line below


In [90]:
EL = xf - (yf/E_Al)
EL


Out[90]:
0.024997268125730065

We can print out the ductility using an f-string.


In [91]:
print(f'the ductility is {round(EL*100,3)}%')


the ductility is 2.5%

Summary

The final properties of our Aluminum sample


In [104]:
print(f'The tensile strength is {round(TS,1)} ksi')
print(f'The yield strength is {round(YS,1)} ksi')
print(f'The elastic modulus is {round(E_Al,0)} ksi')
print(f'the ductility is {round(EL*100,3)}%')


The tensile strength is 48.1 ksi
The yield strength is 46.3 ksi
The elastic modulus is 9555.0 ksi
the ductility is 2.5%

In [ ]: