Skip to content

Arrows disappear when using cartopy transformation #175

@wilkens

Description

@wilkens

adjust_text works great in most situations. But I'm having a small problem using it with cartopy for mapping. The results are as expected, but the arrows linking labels to markers are missing.

A minimal example and resulting figure are below. I'm probably doing something wrong, but I notice that the cartopy example in the documentation may suffer from the same issue? Any thoughts or help are greatly appreciated. Thanks!

adjustText version 1.1.1
cartopy version 0.23.0

from   adjustText import adjust_text
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt

lons = [-98, -100]
lats = [40, 40]
labels = ['One', 'Two']

fig = plt.figure(figsize=(12,6))
ax = plt.axes(projection=ccrs.Robinson())
ax.set_extent([-175, 175, -60, 85], crs=ccrs.Geodetic())
plt.scatter(
    x=lons, 
    y=lats,
    transform=ccrs.Geodetic()
)
texts = []
for i, label in enumerate(labels):
    texts.append(
        ax.text(
            lons[i], 
            lats[i], 
            label, 
            transform=ccrs.Geodetic()
           )
    )
adjust_text(texts, arrowprops=dict(arrowstyle="-", color='k'), ax=ax)
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.BORDERS)

fig.canvas.draw()
plt.show()

adjusttext_issue

The issue seems to come from adding the transform=ccrs.Geodetic() line to the ax.text call. If I leave that out, I see proper arrows, but of course the labels and arrows are in the wrong place, since they aren't transformed to match the axes.

Here's an example of the actual figure I'm trying to produce, where the missing-arrow problem is clearer:
world_map_all

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions