<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 In this post, we'll use data from a tensile test to build a stress strain curve with Python and Matplotlib.
A tensile test is a type of mechanical test performed by engineers used to determine the mechanical properties of a material. Engineering metal alloys such as steel and aluminum alloys are tensile tested in order to determine their strength and stiffness. Tensile tests are performed in a piece of equipment called a mechanical test frame.
After a tensile test is complete, a set of data is produced by the mechanical test frame. Using the data acquired during a tensile test, a stress-strain curve can be produced. 
In this post, we will create a stress-strain curve (a plot) from a set of tensile test data of a steel 1045 sample and an aluminum 6061 sample. The stress strain curve we construct will have the following features
Step1:  Ensure the two .xls data files are in the same folder as the Jupyter notebook
Before we proceed, let's make sure the two .xls data files are in the same folder as our running Jupyter notebook. We'll use a Jupyter notebook magic command to print out the contents of the folder that our notebook is in. The %ls command lists the contents of the current folder.
Step2:  We can see our Jupyter notebook stress_strain_curve_with_python.ipynb as well as the two .xls data files aluminum6061.xls and steel1045.xls are in our current folder. 
Now that we are sure the two .xls data files are in the same folder as our notebook, we can import the data in the two two .xls files using Panda's pd.read_excel() function. The data from the two excel files will be stored in two Pandas dataframes called steel_df and al_df.
Step3:  We can use Pandas .head() method to view the first five rows of each dataframe.
Step4:  We see a number of columns in each dataframe. The columns we are interested in are FORCE, EXT, and CH5. Below is a description of what these columns mean.
FORCE Force measurements from the load cell in pounds (lb), force in pounds
EXT Extension measurements from the mechanical extensometer in percent (%), strain in percent
CH5 Extension readings from the laser extensometer in percent (%), strain in percent
Create stress and strain series from the FORCE, EXT, and CH5 columns
Next we'll create a four Pandas series from the ['CH5'] and ['FORCE'] columns of our al_df and steel_df dataframes. The equations below show how to calculate stress, $\sigma$, and strain, $\epsilon$, from force $F$ and cross-sectional area $A$. Cross-sectional area $A$ is the formula for the area of a circle. For the steel and aluminum samples we tested, the diameter $d$ was $0.506 \ in$.
$$ \sigma = \frac{F}{A_0} $$
$$ F \ (kip) = F \ (lb) \times 0.001 $$
$$ A_0 = \pi (d/2)^2 $$
$$ d = 0.506 \ in $$
$$ \epsilon \ (unitless) = \epsilon \ (\%) \times 0.01 $$
Step5:  Build a quick plot
Now that we have the data from the tensile test in four series, we can build a quick plot using Matplotlib's plt.plot() method. The first x,y pair we pass to plt.plot() is strain_steel,stress_steel and the second x,y pair we pass in is strain_al,stress_al. The command plt.show() shows the plot.
Step6:  We see a plot with two lines. One line represents the steel sample and one line represents the aluminum sample. We can improve our plot by adding axis labels with units, a title and a legend.
Add axis labels, title and a legend
Axis labels, titles and a legend are added to our plot with three Matplotlib methods. The methods are summarized in the table below.
| Matplotlib method | description | example |
| --- | --- | --- |
| plt.xlabel() | x-axis label | plt.xlabel('strain (in/in)') |
| plt.ylabel() | y-axis label | plt.ylabel('stress (ksi)') |
| plt.title() | plot title | plt.title('Stress Strain Curve') |
| plt.legend() | legend | plt.legend(['steel','aluminum']) |
The code cell below shows these four methods in action and produces a plot.
Step7:  The plot we see has two lines, axis labels, a title and a legend. Next we'll save the plot to a .png image file.
Save the plot as a .png image
Now we can save the plot as a .png image using Matplotlib's plt.savefig() method. The code cell below builds the plot and saves an image file called stress-strain_curve.png. The argument dpi=300 inside of Matplotlib's plt.savefig() method specifies the resolution of our saved image. The image stress-strain_curve.png will be saved in the same folder as our running Jupyter notebook.
<ASSISTANT_TASK:>
Python Code:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
print("NumPy version:",np.__version__)
print("Pandas version:",pd.__version__)
Explanation: In this post, we'll use data from a tensile test to build a stress strain curve with Python and Matplotlib.
A tensile test is a type of mechanical test performed by engineers used to determine the mechanical properties of a material. Engineering metal alloys such as steel and aluminum alloys are tensile tested in order to determine their strength and stiffness. Tensile tests are performed in a piece of equipment called a mechanical test frame.
After a tensile test is complete, a set of data is produced by the mechanical test frame. Using the data acquired during a tensile test, a stress-strain curve can be produced. 
In this post, we will create a stress-strain curve (a plot) from a set of tensile test data of a steel 1045 sample and an aluminum 6061 sample. The stress strain curve we construct will have the following features:
A descriptive title
Axes labels with units
Two lines on the same plot. One line for steel 1045 and one line for aluminum 6061
A legend
Install Python
We are going to build our stress strain curve with Python and a Jupyter notebook. I suggest engineers and problem-solvers download and install the Anaconda distribution of Python. See this post to learn how to install Anaconda on your computer. Alternatively, you can download Python form Python.org or download Python the Microsoft Store.
Install Jupyter, NumPy, Pandas, and Matplotlib
Once Python is installed, the next thing we need to do is install a couple of Python packages. If you are using the Anaconda distribution of Python, the packages we are going to use to build the plot: Jupyter, NumPy, Pandas, and Matplotlib come pre-installed and no additional installation steps are necessary. 
However, if you downloaded Python from Python.org or installed Python using the Microsoft Store, you will need to install install Jupyter, NumPy, Pandas, and Matplotlib separately.  You can install Jupyter, NumPy, Pandas, and Matplotlib with pip (the Python package manager) or install theses four packages with the Anaconda Prompt.
If you are using a terminal and pip, type:
```text
pip install jupyter numpy pandas matplotlib 
```
If you have Anaconda installed and use the Anaconda Prompt, type:
```text
conda install jupyter numpy pandas matplotlib 
```
Open a Jupyter notebook
We will construct our stress strain curve using a Jupyter notebook. See this post to see how to open a Jupyter notebook. 
Make sure to save your Jupyter notebook with a recognizable name.
Download the data and move the data into the same folder as the Jupyter notebook
Next, we need to download the two data files that we will use to build our stress-strain curve. You can download sample data using the links below:
steel1045.xls
aluminum6061.xls
After these .xls files are downloaded, both .xls files need to be moved into the same folder as our Jupyter notebook.
Import NumPy, Pandas, and Matplotlib
Now that our Jupyter notebook is open and the two .xls data files are in the same folder as the Jupyter notebook, we can start coding and build our plot.
At the top of the Jupyter notebook, import NumPy, Pandas and Matplotlib. The command %matplotlib inline is included so that our plot will display directly inside our Jupyter notebook. If you are using a .py file instead of a Jupyter notebook, make sure to comment out %matplotlib inline as this line is not valid Python code.
We will also print out the versions of our NumPy and Pandas packages using the .__version__ attribute. If the versions of NumPy and Pandas prints out, that means that NumPy and Pandas are installed and we can use these packages in our code.
End of explanation
%ls
Explanation: Ensure the two .xls data files are in the same folder as the Jupyter notebook
Before we proceed, let's make sure the two .xls data files are in the same folder as our running Jupyter notebook. We'll use a Jupyter notebook magic command to print out the contents of the folder that our notebook is in. The %ls command lists the contents of the current folder.
End of explanation
steel_df = pd.read_excel("steel1045.xls")
al_df = pd.read_excel("aluminum6061.xls")
Explanation: We can see our Jupyter notebook stress_strain_curve_with_python.ipynb as well as the two .xls data files aluminum6061.xls and steel1045.xls are in our current folder. 
Now that we are sure the two .xls data files are in the same folder as our notebook, we can import the data in the two two .xls files using Panda's pd.read_excel() function. The data from the two excel files will be stored in two Pandas dataframes called steel_df and al_df.
End of explanation
steel_df.head()
al_df.head()
Explanation: We can use Pandas .head() method to view the first five rows of each dataframe.
End of explanation
strain_steel = steel_df['CH5']*0.01
d_steel = 0.506    # test bar diameter = 0.506 inches
stress_steel = (steel_df['FORCE']*0.001)/(np.pi*((d_steel/2)**2))
strain_al = al_df['CH5']*0.01
d_al = 0.506       # test bar diameter = 0.506 inches
stress_al = (al_df['FORCE']*0.001)/(np.pi*((d_al/2)**2))
Explanation: We see a number of columns in each dataframe. The columns we are interested in are FORCE, EXT, and CH5. Below is a description of what these columns mean.
FORCE Force measurements from the load cell in pounds (lb), force in pounds
EXT Extension measurements from the mechanical extensometer in percent (%), strain in percent
CH5 Extension readings from the laser extensometer in percent (%), strain in percent
Create stress and strain series from the FORCE, EXT, and CH5 columns
Next we'll create a four Pandas series from the ['CH5'] and ['FORCE'] columns of our al_df and steel_df dataframes. The equations below show how to calculate stress, $\sigma$, and strain, $\epsilon$, from force $F$ and cross-sectional area $A$. Cross-sectional area $A$ is the formula for the area of a circle. For the steel and aluminum samples we tested, the diameter $d$ was $0.506 \ in$.
$$ \sigma = \frac{F}{A_0} $$
$$ F \ (kip) = F \ (lb) \times 0.001 $$
$$ A_0 = \pi (d/2)^2 $$
$$ d = 0.506 \ in $$
$$ \epsilon \ (unitless) = \epsilon \ (\%) \times 0.01 $$
End of explanation
plt.plot(strain_steel,stress_steel,strain_al,stress_al)
plt.show()
Explanation: Build a quick plot
Now that we have the data from the tensile test in four series, we can build a quick plot using Matplotlib's plt.plot() method. The first x,y pair we pass to plt.plot() is strain_steel,stress_steel and the second x,y pair we pass in is strain_al,stress_al. The command plt.show() shows the plot.
End of explanation
plt.plot(strain_steel,stress_steel,strain_al,stress_al)
plt.xlabel('strain (in/in)')
plt.ylabel('stress (ksi)')
plt.title('Stress Strain Curve of Steel 1045 and Aluminum 6061 in tension')
plt.legend(['Steel 1045','Aluminum 6061'])
plt.show()
Explanation: We see a plot with two lines. One line represents the steel sample and one line represents the aluminum sample. We can improve our plot by adding axis labels with units, a title and a legend.
Add axis labels, title and a legend
Axis labels, titles and a legend are added to our plot with three Matplotlib methods. The methods are summarized in the table below.
| Matplotlib method | description | example |
| --- | --- | --- |
| plt.xlabel() | x-axis label | plt.xlabel('strain (in/in)') |
| plt.ylabel() | y-axis label | plt.ylabel('stress (ksi)') |
| plt.title() | plot title | plt.title('Stress Strain Curve') |
| plt.legend() | legend | plt.legend(['steel','aluminum']) |
The code cell below shows these four methods in action and produces a plot.
End of explanation
plt.plot(strain_steel,stress_steel,strain_al,stress_al)
plt.xlabel('strain (in/in)')
plt.ylabel('stress (ksi)')
plt.title('Stress Strain Curve of Steel 1045 and Aluminum 6061 in tension')
plt.legend(['Steel 1045','Aluminum 6061'])
plt.savefig('stress-strain_curve.png', dpi=300, bbox_inches='tight')
plt.show()
Explanation: The plot we see has two lines, axis labels, a title and a legend. Next we'll save the plot to a .png image file.
Save the plot as a .png image
Now we can save the plot as a .png image using Matplotlib's plt.savefig() method. The code cell below builds the plot and saves an image file called stress-strain_curve.png. The argument dpi=300 inside of Matplotlib's plt.savefig() method specifies the resolution of our saved image. The image stress-strain_curve.png will be saved in the same folder as our running Jupyter notebook.
End of explanation
<END_TASK>