basemap: Some countries borders not showing up in map

I remember seeing this already a long time ago but I never managed to solve it.

I’m plotting a map using this

m = Basemap(projection='merc',
                llcrnrlat=extents[2],
                urcrnrlat=extents[3],
                llcrnrlon=extents[0],
                urcrnrlon=extents[1],
                lat_ts=20,
                resolution='h')

m.fillcontinents(color='lightgray', lake_color='#2081C3', zorder=1)
m.drawlsmask(land_color=(0, 0, 0, 0), ocean_color='#2081C3',
                 resolution='f', lakes=True, zorder=2, grid=1.25)

ax = plt.gca()

m.drawcountries(linewidth=0.8)
m.drawcoastlines()

m.readshapefile(f'{SHAPEFILES_DIR}/ITA_adm_shp/ITA_adm1',
                        'ITA_adm1', linewidth=0.8, color='black', zorder=5)

but some countries (like Switzerland) don’t show up.

realtime_wind_italia

Weirdly enough when centering the projection over France Switzerland shows up

realtime_wind_francia

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 23 (12 by maintainers)

Commits related to this issue

Most upvoted comments

I think you can just remove the pip part altogether, those packages shouldn’t be important.

Anyway I decided to create a new environment from scratch with the dependencies I need, which successfully installed also the latest basemap version. I’ll just need to move the production pipeline to this environment once I have some time.

thank you anyway for the help @molinav !!

I have just released basemap 1.3.9 on PyPI and conda-forge, which includes the bugfix for the missing country borders. If there is still any problem on your side, feel free to reopen the issue.

Hi @guidocioni! Sorry for being so late with this. For the moment, I can confirm you the bug using the following code snippet:

import sys
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import __version__ as basemap_version
from mpl_toolkits.basemap import Basemap

print("Python version: ", sys.version)
print("Basemap version:", basemap_version)

plt.clf()
ax = plt.gca()

extents = [6.0, 19.0, 36.0, 47.7]
bmap = Basemap(projection="merc",
               llcrnrlat=extents[2],
               urcrnrlat=extents[3],
               llcrnrlon=extents[0],
               urcrnrlon=extents[1],
               lat_ts=20,
               resolution="h")

bmap.drawcountries(linewidth=1, color="blue")
bmap.drawcoastlines(linewidth=1, color="red")

This returns the following in my console:

Python version:  3.11.2 (tags/v3.11.2:878ead1, Feb  7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)]
Basemap version: 1.3.8

And the following image is obtained, with Switzerland borders missing, as in your original message: missing_switzerland_border

I would need to check the internals of Basemap.drawcountries, to see if the Switzerland borders are read correctly from the basemap_data_hires files (which I would expect), and at which point the borders are filtered out from plotting.