For a project I need to create a visualization that draws a circle around some locations on a map. The visualization used Cartopy v.0.18.0 to render the map. It uses the GoogleTiles
class to fetch and display the tiles in the relevant region, and the add_patch(Patch.Circle(..., transform=ccrs.PlateCarree()))
method to draw the circle.
tiles = GoogleTiles()
fig = plt.figure(figsize=(15,15))
ax = fig.add_subplot(1, 1, 1, projection=tiles.crs)
ax.set_extent((-121.8,-122.55,37.25,37.85))
ax.add_image(tiles, 11)
ax.add_patch(Patch.Circle(xy=[-122.4015173428571, 37.78774634285715], radius = 0.021709041989311614 + 0.005, alpha=0.3, zorder=30, transform=ccrs.PlateCarree()))
plt.show()
However, although I tried several transform objects I either got a ellipse instead of a circle (e.g. using ccrs.PlateCarree()
) or no circle at all (e.g. using ccrs.Mercator()
).
I found several different solutions online (e.g. Drawing Circles with cartopy in orthographic projection), however, these were not for the Mercator projection and I sadly lack the projection/transformation knowledge to adapt these to my problem.
The only way I was able to produce a circular patch, was when I set the projection
parameter on fig.add_subplot
to ccrs.PlateCarree()
. This, however, distorts the map and the labels become blured, so this is sadly not an acceptable solution.
As the project is due soon, a speedy reply would be much appreciated.