Skip to content

Contextily basemap tiles not displaying correctly when using a projected CRS #333

@chudlerk

Description

@chudlerk

I am trying to use contextily tiles to display a basemap on an axis.

If I set up like this:

import matplotlib.pyplot as plt
import ultraplot as uplt
import contextily as cx
import cartopy.crs as ccrs

#set up max extent
lon_min, lon_max = -123.0, -121.5
lat_min, lat_max = 36.8, 38.5
c_lon = (lon_min + lon_max)/2
c_lat = (lat_min + lat_max)/2

#set up unprojected CRS
crs = ccrs.PlateCarree()

I can make a map with a basemap using Cartopy like this

#make unprojected map with Cartopy
fig, ax = plt.subplots(subplot_kw={"projection": crs})
ax.set_extent([lon_min, lon_max, lat_min, lat_max], crs=ccrs.PlateCarree())
cx.add_basemap(ax=ax, crs=crs)
plt.show()

And the Ultraplot equivalent to this is

#make unprojected map with Ultraplot
fig,ax = uplt.subplots(proj=crs, lonlim=(lon_min, lon_max), latlim=(lat_min, lat_max))
cx.add_basemap(ax=ax, crs=crs)
uplt.show()

These two code snippets make nearly identical maps.

However, issues arise when I try to use a projected CRS

#set up projected CRS
proj_crs = ccrs.LambertConformal(central_latitude=c_lat, central_longitude=c_lon)

#make projected map with Cartopy
fig, ax = plt.subplots(subplot_kw={"projection": proj_crs})
ax.set_extent([lon_min, lon_max, lat_min, lat_max], crs=ccrs.PlateCarree())
cx.add_basemap(ax=ax, crs=proj_crs)
plt.show()

#make projected map with Ultraplot
fig,ax = uplt.subplots(proj=proj_crs, lonlim=(lon_min, lon_max), latlim=(lat_min, lat_max))
cx.add_basemap(ax=ax, crs=proj_crs)
uplt.show()

The cartopy map looks fine:
Image

But the Ultraplot version is all wonky:
Image

I noticed the issue appear suddenly when using the legacy version of this package, proplot. Interestingly, the above code used to all work fine, projected CRS and all. To my knowledge, it just suddenly stopped working, without me updating any packages or anything. Love it when that happens... (although I'm willing to concede I may have updated something without knowing/remembering it).

I was unsure if this should go in this GitHub, or the contextily one. Let me know if it belongs in the other one!

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem rightwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions