How To Draw Particle Size Distribution Curve
We will learn how to plot a soil sample's particle size distribution curve with Python and Matplotlib throughout this tutorial. After completing this tutorial, you should know:
- how to calculate a grain size distribution curve
- what a grain size distribution curve is
- how to plot a grain size distribution curve using Python and Matplotlib.
If this sounds interesting to you, then let's jump in and get started!
What is a Grain Size Distribution Curve?
A particle size distribution curve or grain size distribution curve represents the size range of soil grains in a given soil mass as percentages of the total dry weight. Engineers or lab technicians perform a sieve analysis for coarse-grain soils such as gravels and sands and hydrometer analysis for fine-grained soils like silts and clays to determine the soil sample's grain size distribution.
If you would like to download the code and follow along, all the code for this tutorial is available at my Github repository.
Sieve Analysis Results
Let's assume we finished a sieve analysis that has the following results:
Sieve Opening (mm) | Mass Retained (g) |
4.75 | 0 |
2.00 | 17.6 |
0.850 | 56.3 |
0.425 | 108.2 |
0.250 | 91.9 |
0.150 | 94.1 |
0.075 | 57.6 |
Pan | 25.0 |
From the sieve analysis, we can determine the percent finer for each sieve, the percentage of the soil passing through the sieve, and plot the grain size distribution curve.
Calculating Percent Finer
First, we need to define a dictionary with two lists: one for the sieve opening and another for the mass retained. Then we create a pandas DataFrame from the data.
from pandas import DataFrame data = { "opening": [4.75, 2.00, 0.850, 0.425, 0.250, 0.150, 0.075, 0], "mass_retained": [0, 17.6, 56.3, 108.2, 91.9, 94.1, 57.6, 25.0] } df = DataFrame(data)
This is what the the DataFrame df
looks like:
Perfect, now let's create a function called calculate_percent_finer
that will calculate the percent finer for each sieve and create a new column in our DataFrame called percent_finer
.
def calculate_percent_finer(df): total_mass = df.mass_retained.sum() arr = [] for count, sieve in enumerate(df.opening.values): cumulative_mass = sum([df.mass_retained.values[i] for i in range(count + 1)]) percent_finer = ((total_mass - cumulative_mass) / total_mass) * 100 arr.append(percent_finer) return df.assign(p_finer = arr)
Here's what the new DataFrame looks like that the function returns:
The calculate_percent_finer
function takes in the DataFrame as a single argument and returns a new DataFrame with a percent_finer
column. Perfect, we now have all the components needed to plot the grain size distribution curve.
import matplotlib.pyplot as plt df2 = calculate_percent_finer(df) plt.style.use("bmh") plt.semilogx(df2.opening, df2.p_finer) plt.gca().invert_xaxis() plt.xlabel("Grain Size (mm) -- log scale") plt.ylabel("Percent Passing") plt.show()
To plot the grain size distribution curve, we import matplotlib.pyplot
as plt
and use the semilogx()
method to graph a semilog graph. The x-axis is plotted in ascending order by default. So we can use the invert_xaxis
method to reverse the x-axis. Lastly, we add some labels to the plot and show the graph.
Summary
That's how we can plot a particle size distribution curve with Python, Pandas, and Matplotlib. I hope you all found this tutorial helpful. As always, if you have any questions, leave a comment below, and I will do my best to help out!
For more tutorials on using Python for geotechnical engineering related topics, check out my tutorial: How to Plot a Soil's Flow Curve with Python or How to Create a Scatter Plot using Seaborn and Matplotlib.
You have Successfully Subscribed!
How To Draw Particle Size Distribution Curve
Source: https://engineertodeveloper.com/create-particle-size-distribution-curve-with-python/
Posted by: sailerimalk1982.blogspot.com
0 Response to "How To Draw Particle Size Distribution Curve"
Post a Comment