In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
import matplotlib as mpl
import sys
%matplotlib inline
%config InlineBackend.figure_format = 'svg'   #uses high resolution vectorized output
plt.rcParams['figure.figsize'] = (9, 7)

In [2]:
print('Python: ', sys.version)
print('OS: ',sys.platform)
print('pandas version: ', pd.__version__)
print('matplotlib version: ', mpl.__version__)


Python:  3.6.3 |Anaconda custom (64-bit)| (default, Oct 15 2017, 03:27:45) [MSC v.1900 64 bit (AMD64)]
OS:  win32
pandas version:  0.20.3
matplotlib version:  2.2.2

In [3]:
df = pd.read_excel('T574.xls')


WARNING *** OLE2 inconsistency: SSCS size is 0 but SSAT size is non-zero

In [4]:
df


Out[4]:
TESTNUM POINTNUM TIME POSIT FORCE EXT CH5 CH6 CH7 CH8
0 574 1 6.309 0.04426 201.149200 -0.500258 -0.014705 NaN NaN NaN
1 574 2 6.559 0.04494 204.319855 0.000475 -0.012444 NaN NaN NaN
2 574 3 9.160 0.05560 300.833679 0.000366 -0.022041 NaN NaN NaN
3 574 4 9.463 0.05676 315.672058 0.000027 -0.027232 NaN NaN NaN
4 574 5 10.660 0.06176 418.271698 0.001060 -0.025802 NaN NaN NaN
5 574 6 11.664 0.06602 515.416443 0.002550 -0.040543 NaN NaN NaN
6 574 7 12.660 0.06986 609.516052 0.003748 -0.033641 NaN NaN NaN
7 574 8 13.562 0.07374 707.672485 0.004744 -0.047538 NaN NaN NaN
8 574 9 14.360 0.07720 802.403381 0.006188 -0.048686 NaN NaN NaN
9 574 10 15.259 0.08070 901.951721 0.007513 -0.052811 NaN NaN NaN
10 574 11 16.059 0.08414 997.694275 0.008821 -0.064997 NaN NaN NaN
11 574 12 17.060 0.08838 1105.228516 0.010539 -0.058424 NaN NaN NaN
12 574 13 18.064 0.09218 1208.195923 0.012129 -0.052694 NaN NaN NaN
13 574 14 18.758 0.09526 1305.328857 0.013638 -0.044128 NaN NaN NaN
14 574 15 19.564 0.09872 1433.019531 0.015621 -0.046120 NaN NaN NaN
15 574 16 20.163 0.10102 1535.601318 0.016956 -0.038808 NaN NaN NaN
16 574 17 20.763 0.10334 1646.296631 0.018793 -0.023833 NaN NaN NaN
17 574 18 21.258 0.10564 1739.492188 0.019899 -0.026048 NaN NaN NaN
18 574 19 21.960 0.10836 1841.562012 0.021699 -0.023119 NaN NaN NaN
19 574 20 22.464 0.11068 1938.685303 0.023345 -0.015092 NaN NaN NaN
20 574 21 23.062 0.11292 2035.046387 0.024670 -0.007991 NaN NaN NaN
21 574 22 23.564 0.11520 2136.984863 0.026105 -0.005285 NaN NaN NaN
22 574 23 24.163 0.11750 2235.371338 0.028025 0.001207 NaN NaN NaN
23 574 24 24.660 0.11974 2330.586914 0.031142 0.000316 NaN NaN NaN
24 574 25 25.160 0.12164 2423.772705 0.033235 0.004300 NaN NaN NaN
25 574 26 25.659 0.12354 2517.591064 0.035227 -0.004300 NaN NaN NaN
26 574 27 26.062 0.12548 2611.407715 0.036900 -0.004453 NaN NaN NaN
27 574 28 26.560 0.12738 2705.603516 0.038344 -0.005003 NaN NaN NaN
28 574 29 27.064 0.12926 2800.812500 0.040291 -0.010686 NaN NaN NaN
29 574 30 27.459 0.13116 2899.822754 0.041818 -0.006562 NaN NaN NaN
... ... ... ... ... ... ... ... ... ... ...
201 574 202 134.763 0.60002 16307.051758 3.008632 10.864743 NaN NaN NaN
202 574 203 135.266 0.60392 16197.873047 3.008632 11.104694 NaN NaN NaN
203 574 204 135.766 0.60782 16085.024414 3.008632 11.343662 NaN NaN NaN
204 574 205 136.263 0.61246 15952.057617 3.008632 11.576795 NaN NaN NaN
205 574 206 136.662 0.61558 15855.778320 3.008632 11.700356 NaN NaN NaN
206 574 207 137.066 0.61870 15759.117188 3.008632 11.932843 NaN NaN NaN
207 574 208 137.567 0.62332 15619.437500 3.008632 12.173779 NaN NaN NaN
208 574 209 137.964 0.62640 15521.129883 3.008632 12.283292 NaN NaN NaN
209 574 210 138.365 0.62952 15421.300781 3.008632 12.524708 NaN NaN NaN
210 574 211 138.663 0.63260 15318.813477 3.008632 12.644333 NaN NaN NaN
211 574 212 139.063 0.63570 15215.691406 3.008632 12.760253 NaN NaN NaN
212 574 213 139.464 0.63878 15108.013672 3.008632 13.001752 NaN NaN NaN
213 574 214 139.868 0.64188 14998.181641 3.008632 13.122220 NaN NaN NaN
214 574 215 140.165 0.64496 14886.704102 3.008632 13.361867 NaN NaN NaN
215 574 216 140.562 0.64806 14781.804688 3.008632 13.478305 NaN NaN NaN
216 574 217 140.962 0.65112 14662.982422 3.008632 13.707241 NaN NaN NaN
217 574 218 141.267 0.65424 14546.817383 3.008632 13.828823 NaN NaN NaN
218 574 219 141.662 0.65730 14430.142578 3.008632 13.952877 NaN NaN NaN
219 574 220 141.968 0.65966 14336.118164 3.008632 14.068681 NaN NaN NaN
220 574 221 142.364 0.66272 14210.454102 3.008632 14.309159 NaN NaN NaN
221 574 222 142.565 0.66506 14117.692383 3.008632 14.435263 NaN NaN NaN
222 574 223 142.865 0.66738 14021.892578 3.008632 14.553950 NaN NaN NaN
223 574 224 143.167 0.66970 13920.901367 3.008632 14.674150 NaN NaN NaN
224 574 225 143.472 0.67200 13816.618164 3.008632 14.796527 NaN NaN NaN
225 574 226 143.766 0.67432 13715.750000 3.008632 14.914733 NaN NaN NaN
226 574 227 144.067 0.67742 13572.735352 3.008632 15.040310 NaN NaN NaN
227 574 228 144.366 0.67976 13460.220703 3.008632 15.157919 NaN NaN NaN
228 574 229 144.669 0.68206 13341.500977 3.008632 15.293961 NaN NaN NaN
229 574 230 144.964 0.68438 13210.502930 3.008632 15.550070 NaN NaN NaN
230 574 231 144.964 0.68438 13210.502930 3.008632 15.550070 NaN NaN NaN

231 rows × 10 columns


In [5]:
plt.plot(df['CH5'], df['FORCE'])
plt.show()



In [6]:
#df = pd.read_xls('T574.xls')
#print(df)


#plt.plot(df[1], df[2])
#plt.show()

#delta_L = np.array(df[1])*1000  
#print(delta_L)
#force = np.array(df[2])
#print(force)

# sample parameters
#d = 1.778     # diameter of sample in mm
#A0 = np.pi*(d/2)**2 # original cross-sectional area of sample in mm^2
#L0 = 18.002   # original gauge length of sample (lenth of narrowest section)

# calcuate stress and strain
#stress = (force/A0)
#strain = delta_L/L0

# calculate the tensile strength (TS)
#TS = max(stress) # Tensile Strength (TS)
#TS = round(TS,1) # round to 3 sig figs
#print('TS =', TS, 'MPa')

# plot the stress strain curve
#fig, ax1= plt.subplots(1,1)
#plt.plot(strain,stress)
#plt.xlabel('Strain $\epsilon$ (mm/mm)')
#plt.ylabel('Stress $\sigma$ (MPa)')
#plt.title('Stress-Strain Curve of Al6061 - T6')
#plt.axis([0, 1.4, 0, 60])
#plt.grid(True)
#x_minorLocator = MultipleLocator(0.05) #set x-axis minor ticks every 0.05 mm/mm
#ax1.xaxis.set_minor_locator(x_minorLocator)
#y_minorLocator = MultipleLocator(2) #set y-axis minor ticks every 2 MPa
#ax1.yaxis.set_minor_locator(y_minorLocator)
#textstr = r'$TS=%.1f \ MPa$'%(TS)
#bbox_props = dict(boxstyle="round", fc="w", ec="0.5", alpha=0.9)
#plt.text(0.8, 55, textstr, fontsize=14, bbox=bbox_props)

# this is the inset axes over the main axes
#ax2 = plt.axes([0.2, 0.2, .3, .3], facecolor='w')
#plt.plot(strain, stress)
#plt.title('Inset of Elastic Region')
#plt.xlim(0, 0.05)
#plt.ylim(0, 40)
#x_minorLocator = MultipleLocator(0.005) #set x-axis minor ticks every 0.005 mm/mm
#ax2.xaxis.set_minor_locator(x_minorLocator)
#y_minorLocator = MultipleLocator(5) #set y-axis minor ticks every 5 MPa
#ax2.yaxis.set_minor_locator(y_minorLocator)
#plt.show()

#fig.savefig('stress_strain_curve.pdf', bbox_inches='tight')

In [ ]:


In [7]:
df = pd.read_csv('stress_strain_data.csv', sep=',', header=None, skiprows=0)
strain = df[0]
stress = df[1]

In [8]:
# calculate the tensile strength (TS)
TS = max(stress) # Tensile Strength (TS)
TS = round(TS,1) # round to 3 sig figs
print('TS =', TS, 'MPa')

# plot the stress strain curve
fig, ax1= plt.subplots(1,1)
plt.plot(strain,stress, linewidth=3.0)
plt.xlabel('Strain $\epsilon$ (mm/mm)')
plt.ylabel('Stress $\sigma$ (MPa)')
plt.title('Stress-Strain Curve of AISI Steel 1018 in Tension')
plt.axis([0, 0.15, 0, 450])
#plt.grid(True)
x_minorLocator = MultipleLocator(0.005) #set x-axis minor ticks every 0.05 mm/mm
ax1.xaxis.set_minor_locator(x_minorLocator)
y_minorLocator = MultipleLocator(25) #set y-axis minor ticks every 2 MPa
ax1.yaxis.set_minor_locator(y_minorLocator)
ax1.tick_params(axis='y', which='both', right='on', direction='in')
#textstr = r'$TS=%.1f \ MPa$'%(TS)
#bbox_props = dict(boxstyle="round", fc="w", ec="0.5", alpha=0.9)
#plt.text(0.8, 55, textstr, fontsize=14, bbox=bbox_props)

# this is the inset axes over the main axes
ax2 = plt.axes([0.4, 0.22, .4, .4], facecolor='w')
plt.plot(strain, stress, linewidth=3.0)
plt.xlabel('Strain $\epsilon$ (mm/mm)')
plt.ylabel('Stress $\sigma$ (MPa)')
plt.title('Inset Curve')
plt.xlim(0, 0.01)
plt.ylim(0, 300)
x_minorLocator = MultipleLocator(0.0005) #set x-axis minor ticks every 0.005 mm/mm
ax2.xaxis.set_minor_locator(x_minorLocator)
y_minorLocator = MultipleLocator(25) #set y-axis minor ticks every 5 MPa
ax2.yaxis.set_minor_locator(y_minorLocator)
ax2.tick_params(axis='y', which='both', right='on', direction='in')
ax2.tick_params(axis='x', which='both', direction='in')
plt.show()


TS = 413.5 MPa
C:\Users\Peter\Anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py:107: MatplotlibDeprecationWarning: Passing one of 'on', 'true', 'off', 'false' as a boolean is deprecated; use an actual boolean (True/False) instead.
  warnings.warn(message, mplDeprecation, stacklevel=1)

In [49]:
fig.savefig('stress_strain_curve_steel_1018.pdf', bbox_inches='tight')

In [ ]: