2026, Jan 10 01:00

Basemap boundary clipped by Axes? How to disable patch clipping for clean Matplotlib subplot grids

Learn why Basemap map boundaries look shaved in Matplotlib subplots and how to fix the clipping artifact by disabling patch clipping on Axes. steps and code.

Basemap sometimes renders beautiful projections with a small but annoying artifact: the circular map boundary looks shaved off by the Axes on all sides. In a grid of maps this becomes especially obvious, where the boundary line appears uneven and clipped at the edges.

Repro case

The snippet below builds a 3×3 grid and draws a Kavrayskiy VII projection in each panel. The black boundary ring looks like it’s being cut by the subplot frame.

import matplotlib as mpl
from matplotlib import pyplot as plt
import mpl_toolkits.basemap as basemap

canvas = plt.figure(figsize=(7, 4))
outer = canvas.add_gridspec(1, 1)
inner = outer[0].subgridspec(3, 3)

for r in range(3):
    for c in range(3):
        axes_cell = canvas.add_subplot(inner[r, c])
        globe = basemap.Basemap(projection="kav7", lon_0=0, resolution="c", ax=axes_cell)
        globe.fillcontinents(color="#c3c3c3", lake_color="white")
        globe.drawcountries(color="#939393")

What’s going on

The effect stems from rendering the projection as tightly as possible inside the Axes. The stroke width of the map boundary isn’t accounted for, so it extends beyond the Axes area and gets clipped. Changing Axes.margins does not affect this, because the clipping happens at the patch level as the artists are constrained to the Axes’ bounds.

The practical fix

Turning off clipping for the patches in each Axes clears the artifact. It’s a straightforward and effective workaround applied after drawing the map:

import matplotlib as mpl
from matplotlib import pyplot as plt
import mpl_toolkits.basemap as basemap

canvas = plt.figure(figsize=(7, 4))
outer = canvas.add_gridspec(1, 1)
inner = outer[0].subgridspec(3, 3)

for r in range(3):
    for c in range(3):
        axes_cell = canvas.add_subplot(inner[r, c])
        globe = basemap.Basemap(projection="kav7", lon_0=0, resolution="c", ax=axes_cell)
        globe.fillcontinents(color="#c3c3c3", lake_color="white")
        globe.drawcountries(color="#939393")
        [artist.set_clip_on(False) for artist in list(axes_cell.patches)]

This disables clipping for all patch artists on the Axes, allowing the boundary stroke to render without being trimmed at the subplot frame.

Why you should care

In multi-panel figures, small visual artifacts quickly add up. A clipped outline can make a grid look misaligned, distract from the actual data, and give an impression of inconsistent styling across panels. For publications, reports, and dashboards where consistency matters, removing the clipping is a low-effort way to keep the layout clean.

Takeaways

If a Basemap boundary looks truncated, the issue is likely clipping at the Axes limits. Disabling clipping on the Axes patches after drawing the map resolves the problem and preserves a uniform boundary stroke across subplots. Keep this in your toolbox for any grid of projections where the outline must remain visually intact.