Hands-on Tutorials
Subsurface borehole data is collected by drilling and extracting rock or soil core and consists of samples scattered in 3D space that measure different continuous or categorical variables. Each sample records: (1) the 3D spatial coordinates represented by an easting, northing, and elevation, (2) continuous variables such as element concentrations, contaminants, ore grades, or temperature to name a few, and (3) categorical variables such as lithology, alteration, or mineralization units.

Borehole data or similar 3D geospatial datasets are used in the earth sciences and natural resource industries to obtain an understanding of the subsurface for a variety of different applications such as orebody modeling in mining, reservoir mapping in oil and gas, contaminant tracking in hydrogeology, and rock or soil stability delineation for construction or geohazard purposes. Aside from dissemination and analysis purposes, visualizing 3d Geospatial Information is also generally the first step to any subsequent geological modeling, workflows, or exploratory data analyses.
Despite the importance of visualizing borehole data, several earth scientists often rely on expensive software to plot their 3D data as most people working with rocks and soil generally lack extensive programming experience. Plotting 3D borehole data is actually quite easy and can be done with any programming language such as Python (using numpy and matplotlib), R, Octave, or Matlab. Following is a simple tutorial coded in Matlab for visualizing borehole data applied on a real mining dataset from a major copper deposit.
The mining dataset comes in the following format.

Although the tutorial presented is in a mining context, the visualization skills are transferable for the same type of 3D geospatial datasets which are also used in the oil and geotechnical industries as well as in construction, geohazards, and hydrogeology to name a few.
First, we import the mining dataset we will be using and all relevant variables for the demonstration. The dataset contains 16,258 samples scattered throughout a rectangular volume of approximately 3 km in easting, by 2 km in northing, and 1 km in elevation with each sample measuring continuous geochemical element concentrations as well as categorical geological alteration units.
data = importdata('Dataset.txt');
%Spatial coordinates
x = data(:,1); %Easting coordinates in km
y = data(:,2); %Northing coordinates in km
z = data(:,3); %Elevation coordinates in km
%Continuous variables
Cu = data(:,4); %Copper grade in ppm
Mg = data(:,5); %Magnesium grade in wt%
Al = data(:,6); %Aluminum grade in wt%
%Categorical variable
Alte = data(:,7); %Geological alteration unit
Before plotting any of the variables, the geographical coordinates will be used to visualize the location of all samples using the scatter3
function. The scale of the axes should always be equal except for cases where exaggerating the elevation could reveal features that would otherwise be missed due to the data’s spatial extent in the two other principal directions. The axes can be easily scaled by using the axis equal
command in Matlab. The example below compares the 3D scatter plot with unscaled and scaled axes.

Now that we have correctly scaled the axes, we can plot variables using color to represent their values in space. We can also use a logarithmic colorbar or different colors to better visualize certain variables or variable ratios. A couple of examples are shown below using different colorbars and color scales.

Additional dimensions could also be introduced by varying the size or shape of plotted points and this could serve as an additional tool for multidimensional exploratory analyses of spatial data. In the example below, the size of the points is set to equal the aluminum to magnesium ratio (Al/Mg) and the color is used to visualize the copper grade.

The multidimensional plot highlights how higher grades of copper are found at intermediate values of Al/Mg since both the bigger and smaller dots generally have smaller concentrations of copper.
Using geological block models to better visualize different volumes of categorical data
We would like to visualize the four different categorical variables in the mining dataset which are composed of the following geological alteration units: Chlorite-Sericite, Quartz-Sericite, Potassic, and Argillic. One approach to plotting this categorical data would be to create a 3D scatter plot and color each point based on its categorical value as we did with the continuous variables as shown in the example below.

When dealing with categorical data, we obtain more actionable information when visualizing the categorical units or domains as volumes in a block model rather than as points scattered in 3D space. Block models are generated by (1) creating a grid of regularly spaced points throughout the total volume, and (2) assigning a category to each point based on the category of the nearest neighboring sample from the data. For a more representative block model, the points should be filtered to only include those within a set search radius from actual data samples.
This is easy to program and visualize as there are several nearest neighbor libraries available in most programming languages, an example of coding this in Matlab is shown below.
%Step size and radius inputs
SS = 0.01; % Step size in km
r = 0.01; % Search radius in km
xp=0:SS:max(x); yp=0:SS:max(y); zp=0:SS:max(z);
[X,Y,Z] = meshgrid(xp,yp,zp); % Create grid of points
Xp = X(:); Yp = Y(:); Zp = Z(:);
Data_xyz = [x y z]; % Spatial coordinates in matrix
Block_xyz = [Xp Yp Zp]; % Block model coordinates in matrix
[Idx D] = knnsearch(Data_xyz,Block_xyz); % Nearest neighbor search
Block_xyz(:,4) = alte(Idx); % Assign block values an alteration unit to nearest sample
Block_xyz = Block_xyz.*(D<=r); %Filter to search radius
%visualize Block_xyz with scatter3
A small enough step size should be used to populate the volume while keeping a reasonable total point count for ease of processing and visualization. Adequate step sizes will depend on the total volume under consideration with proportionately larger steps for larger volumes and shorter steps for smaller volumes.
For the mining dataset in use, the step size was set to 10 m thus there will be one point every 10 m in all three directions. Different search radii should be tested to determine which one adequately visualizes the volumes. Based on the examples below, a search radius between 66 m and 100 m would be adequate for this dataset.

Finally, the block models of each domain can be plotted separately within the total volume to better visualize the spatial distributions of each domain as shown in the example below.

The block models make it easier to summarize the location of each geological alteration unit:
- The Chlorite-Sericite unit is sloping down from high to low elevations from the West to the East
- The Quartz-Sericite unit is clustered more densely towards the Eastern side of the volume
- The Potassic unit is concentrated at the top of the North-Western corner of the volume
- The Argillic unit is scattered in both the East-West and North-South directions at high elevations
Conclusions
Visualizing borehole data is crucial in the earth sciences and natural resource industries and many geoscientists currently rely on expensive commercial software packages to do so. Plotting 3D geospatial data using any standard programming language is actually quite straightforward and this article has shown a couple of the techniques for visualizing continuous, categorical, and multi-dimensional variables within their 3D spatial context.
Although the tutorial presented here used a mining dataset, the 3D visualization techniques can also be applied to a variety of other applications such as mapping groundwater contaminants, soil strength parameters, rock strength and stability, oil and gas volumes, and subsurface geothermal temperatures to name a few.
Author’s note
I hope this tutorial was useful for all readers, especially for the targeted audience working in the earth sciences or natural resource industries. I’d like to encourage all those working with subsurface borehole data or similar 3D geospatial datasets both in industry and academia to try programming their own visualization scripts rather than just rely on commercial software.
As I progress from academia to industry, I’m currently looking for geospatial data analysis projects to work on which relate to natural resources or the environment. Feel free to reach out to me through email or LinkedIn if you wish to collaborate or potentially establish a new connection in this field!