-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arrows disappear when using cartopy transformation #175
Comments
Thank you for reporting this issue. I tried having a look... These cartopy transforms are weird, I have no experience working with them. Do you have an example how to even add an arrow here that would connect your desired coordinates? |
Thanks for looking into this. I'm definitely no pro with cartopy myself. Here's code that sets the labels and arrows by hand using 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())
# plot the points
plt.scatter(
x=lons,
y=lats,
transform=ccrs.Geodetic()
)
# add the annotations one at a time
ax.annotate(
text='One',
xy=(-98,40),
xytext=(-90,39),
xycoords=ccrs.Geodetic(),
textcoords=ccrs.Geodetic(),
va='center',
ha='left',
arrowprops={'arrowstyle':'-'}
)
ax.annotate(
text='Two',
xy=(-100,40),
xytext=(-110,41),
xycoords=ccrs.Geodetic(),
textcoords=ccrs.Geodetic(),
va='center',
ha='right',
arrowprops={'arrowstyle':'-'}
)
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.BORDERS)
fig.canvas.draw() I don't think the annotations need both |
You are using ax.annotate... The issue is that adjustText just changes the coordinate of the provided So I am a little stumped as to how to fix this, and I suspect that without fixing this error in cartopy I can't fix this problem here in a reasonable way. |
Ah, yeah, I see the problem. I can replicate the It does seem like the solution would be to substitute Thanks for your work on the package. It's been a great help to me on many occasions! |
I think I could add an argument to change the behaviour... Not sure about the best naming. But it could simply use annotate to draw the arrow, and not touch the text. I had it like that in the past... I think the issue was aesthetic - the arrows would sometimes strike through the text for some reason. Maybe it could be solved somehow. |
That would certainly be a help to me if you're up for it. In any case, I'm grateful for all your work on the package. |
Oh, and happy to help test/debug ... |
Can you try the latest commit? For me the arrows work, but they don't get clipped by the text, so can strike through it... |
You probably get a warning when running it, as it suggests you can increase the shrinkA value in arrowprops to reduce the strikethrough... But in some of them the arrow might start some distance away from the text then. |
Yes, that does help. As you say, it's tricky to find the right balance between minimizing both strikethrough and the gap between texts and arrows. When the label is vertically above/below the marker, a small |
adjust_text
works great in most situations. But I'm having a small problem using it withcartopy
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.1cartopy
version 0.23.0The issue seems to come from adding the
transform=ccrs.Geodetic()
line to theax.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:
The text was updated successfully, but these errors were encountered: