One of the first things I do when I receive a new well log dataset is check what data is actually there. Which wells have a full suite of measurements? Which are missing key curves? Before you can do any interpretation or modelling, you need to understand what you are working with.
A heatmap is the natural choice for this. It gives you a birds-eye view of data completeness across multiple wells and measurements in a single figure. The problem is that the default matplotlib heatmap looks awful. It is functional, but you would never put it in a report or a presentation.
In this article, I am going to take a basic matplotlib heatmap and transform it step by step into something polished and professional. Each step changes one thing, and by the end we will have gone from the default to something that is genuinely useful and visually clear.
Creating Our Dataset
Before we start, we need some data. We will create a synthetic dataset that represents a common scenario: 12 wells, each with varying availability of 10 well log measurements. A value of 1 means the measurement is present, and 0 means it is missing.
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import numpy as np
import pandas as pd
np.random.seed(42)
# Well names
wells = [’15/9-F-1’, ‘15/9-F-4’, ‘15/9-F-7’, ‘15/9-F-11’,
‘16/1-2’, ‘16/1-6’, ‘16/1-14’, ‘16/2-3’,
‘25/2-7’, ‘25/2-10’, ‘25/5-1’, ‘25/5-4’]
# Common well log curve mnemonics
curves = [’GR’, ‘RDEP’, ‘RSHA’, ‘RHOB’, ‘NPHI’,
‘DTC’, ‘DTS’, ‘PEF’, ‘CALI’, ‘SP’]
# Generate availability data (1 = present, 0 = missing)
# GR and CALI are almost always present
# DTS, PEF and SP are frequently missing
availability = np.ones((len(wells), len(curves)))
# Make some curves more commonly missing
for i in range(len(wells)):
if np.random.random() > 0.9:
availability[i, 0] = 0 # GR rarely missing
if np.random.random() > 0.7:
availability[i, 5] = 0 # DTC sometimes missing
if np.random.random() > 0.4:
availability[i, 6] = 0 # DTS often missing
if np.random.random() > 0.5:
availability[i, 7] = 0 # PEF often missing
if np.random.random() > 0.6:
availability[i, 9] = 0 # SP often missing
if np.random.random() > 0.8:
availability[i, 3] = 0 # RHOB occasionally missing
if np.random.random() > 0.8:
availability[i, 4] = 0 # NPHI occasionally missing
df_avail = pd.DataFrame(availability, index=wells, columns=curves)
fig, ax = plt.subplots()
ax.imshow(df_avail.values)
plt.show()It technically shows the data, but it is close to useless. There are no labels, the aspect ratio is squashed, the colourmap makes it hard to distinguish between present and missing data, and there is no way to tell which well or curve you are looking at. This is our starting point.
Step 2: Adding Axis Labels
The most obvious problem is the lack of labels. Without them, the heatmap is just a coloured grid with no meaning.
fig, ax = plt.subplots()
ax.imshow(df_avail.values)
ax.set_xticks(range(len(curves)))
ax.set_xticklabels(curves)
ax.set_yticks(range(len(wells)))
ax.set_yticklabels(wells)
plt.show()We can now see which wells and curves we are looking at. But, the x-axis labels are overlapping and the figure is still cramped.
Step 3: Fixing the Figure Size and Aspect Ratio
The default figure size is too small for the amount of data we are showing. We also need to think about the aspect ratio of each cell.
Right now the cells are stretched to fill the figure, which makes the heatmap look distorted.
fig, ax = plt.subplots(figsize=(12, 8))
ax.imshow(df_avail.values, aspect=’auto’)
ax.set_xticks(range(len(curves)))
ax.set_xticklabels(curves)
ax.set_yticks(range(len(wells)))
ax.set_yticklabels(wells)
plt.tight_layout()
plt.show()Setting aspect='auto' lets the cells fill the available space proportionally rather than being forced into squares. The larger figure size gives everything room to breathe.
Step 4: Choosing a Better Colourmap
This is where the biggest visual improvement happens. The default colourmap (viridis) is designed for continuous data, but our data is binary: either the measurement is there or it is not. We need a colourmap that makes this distinction obvious at a glance.
# Create a custom colourmap: red for missing, green for present
cmap = mcolors.ListedColormap([’#e74c3c’, ‘#2ecc71’])
bounds = [-0.5, 0.5, 1.5]
norm = mcolors.BoundaryNorm(bounds, cmap.N)
fig, ax = plt.subplots(figsize=(12, 8))
ax.imshow(df_avail.values, cmap=cmap, norm=norm, aspect=’auto’)
ax.set_xticks(range(len(curves)))
ax.set_xticklabels(curves)
ax.set_yticks(range(len(wells)))
ax.set_yticklabels(wells)
plt.tight_layout()
plt.show()The red and green immediately communicate “missing” and “available” without needing to check a legend. This is a much more natural encoding for binary data than a gradient colourmap.
If you want to keep the heatmap accessible for colour vision deficiency, you could substitute orange/blue or use distinct shades with different luminance values. For example:
# Accessible alternative
cmap = mcolors.ListedColormap([’#d35400’, ‘#2980b9’])Step 5: Rotating and Styling the Tick Labels
The well names along the y-axis are fine, but the curve mnemonics along the x-axis could benefit from some adjustment. Let’s also set a consistent font size and move the x-axis labels to the top, which is a more natural position when reading a table from top to bottom.
cmap = mcolors.ListedColormap([’#e74c3c’, ‘#2ecc71’])
bounds = [-0.5, 0.5, 1.5]
norm = mcolors.BoundaryNorm(bounds, cmap.N)
fig, ax = plt.subplots(figsize=(12, 8))
ax.imshow(df_avail.values, cmap=cmap, norm=norm, aspect=’auto’)
ax.set_xticks(range(len(curves)))
ax.set_xticklabels(curves, fontsize=11, fontweight=’bold’)
ax.set_yticks(range(len(wells)))
ax.set_yticklabels(wells, fontsize=10)
# Move x-axis labels to the top
ax.xaxis.set_ticks_position(’top’)
ax.xaxis.set_label_position(’top’)
# Rotate x labels slightly for readability
plt.setp(ax.get_xticklabels(), rotation=45, ha=’left’)
plt.tight_layout()
plt.show()Moving the labels to the top makes the figure feel more like a data table, which is how most people naturally read data completeness information. The bold font on the curve names draws attention to what you are checking for.
Step 6: Adding Gridlines to Separate Cells
With the colourmap fixed, the cells can start to blend together visually, especially when you have large blocks of the same colour. Adding gridlines helps define each cell and makes it easier to trace a row or column.
cmap = mcolors.ListedColormap([’#e74c3c’, ‘#2ecc71’])
bounds = [-0.5, 0.5, 1.5]
norm = mcolors.BoundaryNorm(bounds, cmap.N)
fig, ax = plt.subplots(figsize=(12, 8))
ax.imshow(df_avail.values, cmap=cmap, norm=norm, aspect=’auto’)
ax.set_xticks(range(len(curves)))
ax.set_xticklabels(curves, fontsize=11, fontweight=’bold’)
ax.set_yticks(range(len(wells)))
ax.set_yticklabels(wells, fontsize=10)
ax.xaxis.set_ticks_position(’top’)
ax.xaxis.set_label_position(’top’)
plt.setp(ax.get_xticklabels(), rotation=45, ha=’left’)
# Add gridlines between cells
ax.set_xticks(np.arange(-0.5, len(curves), 1), minor=True)
ax.set_yticks(np.arange(-0.5, len(wells), 1), minor=True)
ax.grid(which=’minor’, color=’white’, linewidth=2)
ax.tick_params(which=’minor’, size=0)
plt.tight_layout()
plt.show()The white gridlines create clear separation between cells. Using the minor tick positions means the gridlines sit between cells rather than through their centres. Setting size=0 on the minor ticks hides the tick marks themselves while keeping the grid.
Step 7: Adding a Legend or Colour Bar
The red and green colours are fairly intuitive, but we should not rely on assumption. Adding a simple legend or colour bar makes the figure self-explanatory.
from matplotlib.patches import Patch
cmap = mcolors.ListedColormap([’#e74c3c’, ‘#2ecc71’])
bounds = [-0.5, 0.5, 1.5]
norm = mcolors.BoundaryNorm(bounds, cmap.N)
fig, ax = plt.subplots(figsize=(12, 8))
ax.imshow(df_avail.values, cmap=cmap, norm=norm, aspect=’auto’)
ax.set_xticks(range(len(curves)))
ax.set_xticklabels(curves, fontsize=11, fontweight=’bold’)
ax.set_yticks(range(len(wells)))
ax.set_yticklabels(wells, fontsize=10)
ax.xaxis.set_ticks_position(’top’)
ax.xaxis.set_label_position(’top’)
plt.setp(ax.get_xticklabels(), rotation=45, ha=’left’)
ax.set_xticks(np.arange(-0.5, len(curves), 1), minor=True)
ax.set_yticks(np.arange(-0.5, len(wells), 1), minor=True)
ax.grid(which=’minor’, color=’white’, linewidth=2)
ax.tick_params(which=’minor’, size=0)
# Add a legend
legend_elements = [
Patch(facecolor=’#2ecc71’, edgecolor=’white’, label=’Available’),
Patch(facecolor=’#e74c3c’, edgecolor=’white’, label=’Missing’),
]
ax.legend(handles=legend_elements, loc=’lower right’,
fontsize=11, framealpha=0.9, edgecolor=’grey’)
plt.tight_layout()
plt.show()A simple patch legend is cleaner than a colour bar for binary data. It sits neatly in the corner and tells the viewer exactly what they are looking at without cluttering the figure.
Step 8: Final Polish
The last step is about the details that take a figure from good to professional. We add a title, remove unnecessary spines, and make sure everything is consistent.
from matplotlib.patches import Patch
cmap = mcolors.ListedColormap([’#e74c3c’, ‘#2ecc71’])
bounds = [-0.5, 0.5, 1.5]
norm = mcolors.BoundaryNorm(bounds, cmap.N)
fig, ax = plt.subplots(figsize=(12, 9))
im = ax.imshow(df_avail.values, cmap=cmap, norm=norm, aspect=’auto’)
# Axis labels
ax.set_xticks(range(len(curves)))
ax.set_xticklabels(curves, fontsize=11, fontweight=’bold’,
fontfamily=’monospace’)
ax.set_yticks(range(len(wells)))
ax.set_yticklabels(wells, fontsize=10, fontfamily=’monospace’)
# Move x-axis to top
ax.xaxis.set_ticks_position(’top’)
ax.xaxis.set_label_position(’top’)
plt.setp(ax.get_xticklabels(), rotation=45, ha=’left’)
# Gridlines
ax.set_xticks(np.arange(-0.5, len(curves), 1), minor=True)
ax.set_yticks(np.arange(-0.5, len(wells), 1), minor=True)
ax.grid(which=’minor’, color=’white’, linewidth=2)
ax.tick_params(which=’minor’, size=0)
# Remove spines
for spine in ax.spines.values():
spine.set_visible(False)
# Legend outside the heatmap, centred below
legend_elements = [
Patch(facecolor=’#2ecc71’, edgecolor=’white’, label=’Available’),
Patch(facecolor=’#e74c3c’, edgecolor=’white’, label=’Missing’),
]
ax.legend(handles=legend_elements, loc=’upper center’,
bbox_to_anchor=(0.5, -0.02), ncol=2,
fontsize=11, framealpha=0.9, edgecolor=’grey’)
# Title
ax.set_title(’Well Log Data Availability’,
fontsize=16, fontweight=’bold’, pad=40)
# Horizontal line to separate summary from chart
ax.axhline(y=len(wells) - 0.5, color=’grey’, linewidth=0.8,
linestyle=’-’, xmin=0, xmax=1)
# Summary title on the left
ax.text(-0.5, len(wells) + 0.3, ‘Availability %’,
ha=’right’, va=’center’, fontsize=10,
color=’#555555’, fontweight=’bold’, fontfamily=’monospace’)
# Percentage summaries below the line, colour-coded
pct_available = df_avail.mean(axis=0).values * 100
for i, pct in enumerate(pct_available):
color = ‘#e74c3c’ if pct < 60 else ‘#f39c12’ if pct < 80 else ‘#2ecc71’
ax.text(i, len(wells) + 0.3, f’{pct:.0f}%’,
ha=’center’, va=’center’, fontsize=10,
color=color, fontweight=’bold’, fontfamily=’monospace’)
# Extend the y-axis to make room for the summary row
ax.set_ylim(len(wells) + 0.8, -0.5)
plt.tight_layout()
plt.savefig(’heatmap_final.png’, dpi=300, bbox_inches=’tight’,
facecolor=’white’)
plt.show()Here is what we changed in this final step:
Monospace font for well names and curve mnemonics, which is standard for technical identifiers and makes them easier to scan.
Removed spines to clean up the edges. The gridlines already define the structure so the border is redundant.
Added a title with extra padding to clear the rotated x-axis labels.
Moved the legend outside the heatmap and centred it below the chart. This avoids covering any cells and keeps the data area clean.
Added a separated summary row below the heatmap with a horizontal divider line and an “Availability %” label. The percentages are colour-coded: green for 80% and above, amber for 60–79%, and red for below 60%. This turns the figure from a simple display into something actionable. You can immediately see that GR and CALI are available in 100% of wells while PEF drops to just 42%.
Saved at 300 DPI for print quality.
The Full Transformation
Let’s look at where we started and where we ended up.
The default imshow() call gave us a squashed, unlabelled, rainbow-gradient mess. Through eight incremental changes, we now have a figure with:
A clear binary colourmap that communicates status at a glance
Properly labelled and positioned axes
Grid separation between cells
A self-explanatory legend
Percentage summaries for quick assessment
Clean styling suitable for a report or presentation
None of these steps involved complex code. Each one was a small, targeted improvement. That is the key takeaway: you do not need to overhaul everything at once. Pick one thing, make it better, and move on to the next.
Bonus: Extending to Continuous Data
The same principles apply when your heatmap shows continuous values rather than binary availability. If you were plotting the percentage of valid readings per curve per well (rather than just present/absent), you would swap the binary colourmap for a sequential one and add text annotations.
# Example: percentage of valid readings per curve
pct_data = df_avail.values * np.random.uniform(0.6, 1.0, size=df_avail.shape)
pct_data = np.where(df_avail.values == 0, 0, pct_data)
fig, ax = plt.subplots(figsize=(12, 8))
im = ax.imshow(pct_data, cmap=’RdYlGn’, vmin=0, vmax=1, aspect=’auto’)
# Add percentage text to each cell
for i in range(len(wells)):
for j in range(len(curves)):
value = pct_data[i, j]
text_color = ‘white’ if value < 0.5 else ‘black’
ax.text(j, i, f’{value:.0%}’, ha=’center’, va=’center’,
fontsize=9, color=text_color, fontweight=’bold’)
ax.set_xticks(range(len(curves)))
ax.set_xticklabels(curves, fontsize=11, fontweight=’bold’,
fontfamily=’monospace’)
ax.set_yticks(range(len(wells)))
ax.set_yticklabels(wells, fontsize=10, fontfamily=’monospace’)
ax.xaxis.set_ticks_position(’top’)
ax.xaxis.set_label_position(’top’)
plt.setp(ax.get_xticklabels(), rotation=45, ha=’left’)
ax.set_xticks(np.arange(-0.5, len(curves), 1), minor=True)
ax.set_yticks(np.arange(-0.5, len(wells), 1), minor=True)
ax.grid(which=’minor’, color=’white’, linewidth=2)
ax.tick_params(which=’minor’, size=0)
for spine in ax.spines.values():
spine.set_visible(False)
cbar = plt.colorbar(im, ax=ax, shrink=0.8, pad=0.02)
cbar.set_label(’Data Completeness’, fontsize=11)
ax.set_title(’Well Log Data Completeness’,
fontsize=16, fontweight=’bold’, pad=40)
plt.tight_layout()
plt.show()The RdYlGn (Red-Yellow-Green) colourmap works well here because it maps naturally to the idea of bad-ok-good. The text annotations give exact values while the colour gives the overall pattern. This combination of colour and text is much more effective than either one alone.
Summary
Transforming a matplotlib heatmap from default to publication-ready does not require specialist knowledge. It takes eight small, deliberate steps:
Start with the raw default
Add axis labels
Fix the figure size and aspect ratio
Choose an appropriate colourmap
Style and position the tick labels
Add gridlines to define cells
Include a legend or colour bar
Polish with title, fonts, and summary statistics
Each step improves one thing. By the end, the figure communicates its message clearly and looks professional enough for any report or presentation.
The same approach works for any chart type. Start with the default, identify what is not working, and fix one thing at a time. You will be surprised how quickly the figure transforms.
The dataset used in this article is synthetic but based on typical well log data availability patterns from the Norwegian Continental Shelf. The well naming convention follows the standard Norwegian quadrant/block/well format.











