Cartopy: Gridliner tick labels are attached to background patch, not to the boundary spines

Created on 29 Apr 2020  路  7Comments  路  Source: SciTools/cartopy

Description

When panning on a map, the tick labels are attached to the background and move around with the pan. I would expect them to be attached to the boundary and be right on the axes spines.
Here is an example where I panned over a little bit.
Figure_1

I came across this looking at the recent Gridliner example in #1537

@stefraynaud, I'm going to ping you here since you've dealt a lot with the gridliner ticks.

Code to reproduce

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker

lambert_crs = ccrs.LambertConformal(central_longitude=105) 

ax0 = plt.axes(projection=lambert_crs)
ax0.set_extent([75, 130, 18, 54], crs=ccrs.PlateCarree())
ax0.add_feature(cfeature.LAND)
ax0.add_feature(cfeature.BORDERS)
gl = ax0.gridlines(draw_labels=True, dms=True, x_inline=False, y_inline=False)
gl.xlocator = mticker.FixedLocator([70, 80, 90, 100, 110, 120, 130])
gl.ylocator = mticker.FixedLocator([10, 20, 30, 40, 50])
gl.rotate_labels = False
gl.top_labels = gl.right_labels = False
ax0.coastlines(resolution='10m')
plt.show()


Full environment definition
Reproduced on both macosx and qt5agg backends.

matplotlib==3.2.0
cartopy==0.18.0b3.dev25+

Cartopy version

master

Most helpful comment

Here is a first overview.
gridliner

All 7 comments

Sorry, I was not able to reproduce the figure.
The algo uses self.axes.patch.get_path(), which seems to be synced with self.axes.spines['geo'].get_path().
It does not use other self.axes.spines entries since they do not always coincide with the map boundary. However, as slightly suggested in #1530, we should probably take them into account to better determine the real side of a label.

I'm able to reproduce this on both macosx and qt5agg backends. What environment are you using? It could be something to do with different versions of MPL or a backend...

The versions of mpl and Cartopy I'm using are: matplotlib==3.2.0 and cartopy==0.18.0b3.dev25+.

I've been able to reproduce it by playing with the zoom tool in intercative mode.
I already successfully tried a solution:

  • connect the draw event to the _draw_gridliner method
  • remove all lines and labels already plotted at the beginning of _draw_gridliner
  • then do the normal stuff

This means that lines and labels are recomputed and redrawn everytime, but it works well.
I can update the PR #1538.

I'd say those are two different features, so a new different PR may be better?

What you say makes sense to me. I only wonder if you need to redraw every single time, or if you can just update the transforms/locations of the already drawn items so that it can be rendered faster by keeping the same artists that are already present?

I agree with about creating another PR, once PR #1537 (not #1538) is merged.
So this is more for 0.19.

About refreshing, It seems to be fast enough to be acceptable, since only the lines and labels are redrawn. The point of doing it this way is that when you zoom in for instance, you may quickly no longer have grid line and label. This makes the system really nice!

Here is a first overview.
gridliner

I'm ready to make a PR, once #1537 is ok since the former starts from the latter.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MarkWieczorek picture MarkWieczorek  路  9Comments

leecronce picture leecronce  路  8Comments

chengzhuzhang picture chengzhuzhang  路  8Comments

pelson picture pelson  路  4Comments

maxnoe picture maxnoe  路  5Comments