Closed senesis closed 9 months ago
Thanks again for the note here.
It looks like my recommendation from the prior issue (#210) isn't as robust as I'd hoped and probably not a great way to handle that situation. I'll update the conversation there to reflect this in a moment.
However, gv.set_axes_limits_and_ticks
should do the trick as shown below and hopefully be more robust. Setting ticks via the recommended methods in cartopy should also work.
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import cartopy.feature as cfeature
import geocat.viz as gv
fig = plt.figure(figsize=(6, 3))
projection = ccrs.PlateCarree(central_longitude=180)
ax = plt.axes(projection=projection)
ax.add_feature(cfeature.LAND, color='silver',zorder=1)
gv.set_axes_limits_and_ticks(ax,
xticks=[-180,-90,0,90,180],
yticks=[-90,0,90])
gv.add_lat_lon_ticklabels(ax)
plt.show()
I'm going to close this issue for now and follow up on the original issue, but please feel free to reopen if you have questions and/or this doesn't address your problem.
From the documentation, gv.add_lat_lon_ticklabels()
is a : "Utility function to make plots look like NCL plots by adding latitude, longitude tick labels"
Its baseline use is to avoid having to compute the set of tick locations. So, the solution you propose does not meet that requirement.
So I am afraid that this issue cannot be closed.
Sorry for the confusion.
Certainly the description and documentation is at the very least is misleading as it stands regarding add_major_minor_ticks
and add_lat_lon_ticklabels
and the need to set ticks prior to using these functions (as described in your issue #210). Ideally we would address this in the code as well so additional steps are not needed. This should be addressed by that issue.
This particular issue #213 though seemed to relate to the crash/error from the combination of my original suggestion and the projection described above which can be addressed by the updated suggestion here and in #210. My intent with closing this issue was to indicate that this was now a duplicate of #210 rather than its own issue not necessarily that it had been fully addressed.
Describe the bug
add_lat_lon_ticklabels
crashes forPlateCarre(central_longitude=180)
, while there is no issue ifcentral_longitude=0
. And by the way, when NOT callingadd_lat_lon_ticklabels
, the labels doesn't take account of the value ofcentral_longitude
!To Reproduce Execute this code, setting central_longitude first to
0
, then to 180. And also one more time commenting out the call toadd_lat_lon_ticklabels
Screenshots Here is the crash report for
central_longitude=180
.OS: see #210
Environment see #210