1

Recently I updated to matplotlib 3.3.1 on python 3.8. I use cartopy version 0.18.0. With this version, the background image interpolation seems to work anymore. Does anyone have a workaround/soultion? Here is a minimum reproducible example:

import matplotlib.pyplot as plt
import cartopy as ccrs
import cartopy.io.img_tiles as cimgt

fig, ax = plt.subplots(subplot_kw=dict(projection=ccrs.crs.PlateCarree()))
ax.set_extent([67, 75, 20, 26])
ax.add_image(cimgt.GoogleTiles(), 8, interpolation='spline36')

Which throws an error:

TypeError: got an unexpected keyword argument 'interpolation'

Vinod Kumar
  • 1,383
  • 1
  • 12
  • 26
  • 1
    What is your desired outcome? What version of `cartopy` supported the 'interpolation' argument to `cartopy.mpl.geoaxes.GeoAxes.add_image`? `add_image` currently does not allow any args or kwargs https://github.com/SciTools/cartopy/blob/4069ad818d5fe948c1eac7d1cbe81b9425eca491/lib/cartopy/mpl/geoaxes.py#L422 – rlchqrd Oct 14 '20 at 22:15
  • I was using same verison of cartopy, but with matplotlib 3.1 on python 3.6. I need interpolation for better looking map. For example, see https://stackoverflow.com/questions/49155110/why-do-my-google-tiles-look-poor-in-a-cartopy-map – Vinod Kumar Oct 14 '20 at 22:50

1 Answers1

0

If you need better resolution images, you need to increase the scale value. In your code, you can change 8 to 10 as a new experiment.

ax.add_image(cimgt.GoogleTiles(), 10)

Edit1

Since the use of projection (crs.PlateCarree()) different from the original (crs.Mercator()) causes the image's reprojection at the time of rendering, and results in unsatisfactory image quality. And this type of images, with sharp edges/lines, symbols, and texts, are difficult to get a good result from reprojection or interpolation. Let's use the original projection to plot the map and investigate the result.

import matplotlib.pyplot as plt
import cartopy as ccrs
import cartopy.io.img_tiles as cimgt

tiles = cimgt.GoogleTiles()
image_crs = tiles.crs

fig, ax = plt.subplots(figsize=(16,12), subplot_kw=dict(projection=image_crs))

ax.set_extent([67, 75, 20, 26], crs=ccrs.crs.PlateCarree())

ax.add_image(cimgt.GoogleTiles(), 8)
plt.show()

The output plot:

rajkot

swatchai
  • 17,400
  • 3
  • 39
  • 58
  • Thanks for pointing this out. However, the scale parameter just adds more details, but the map quality does not improve. Please see the discussion at https://github.com/SciTools/cartopy/issues/1048 – Vinod Kumar Oct 26 '20 at 07:45
  • @VinodKumar Is the new approach gives better image quality? – swatchai Oct 26 '20 at 09:44
  • This indeed improves image quality, but I would prefer not to skip projection (crs.PlateCarree()). This is required for adding further data overlays on the map. – Vinod Kumar Oct 26 '20 at 11:31
  • If other data overlays are vector, no problem on web-mercator projection. Only certain types of raster data will fails when reprojected. – swatchai Oct 26 '20 at 13:10