我试图隐藏右侧的标签(又名纬度)在这个Cartopy map 使用right_labels = False
,但只适用于某些值.但是,可以使用top_labels = False
和bottom_label=False
隐藏顶部/底部标签.
复制:
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import matplotlib.ticker as mticker
import matplotlib.path as mpath
import cartopy.feature as cf
"""
Plot Alaska
"""
# Map View Using Cartopy
fig = plt.figure(figsize=(8,6))
xmin=-163
xmax=-120
ymin=50
ymax=71
proj = ccrs.LambertConformal(central_longitude=(xmin+xmax)/2, central_latitude=(ymin+ymax)/2)
ax = fig.add_subplot(1, 1, 1, projection=proj)
n = 20
aoi = mpath.Path(
list(zip(np.linspace(xmin, xmax, n), np.full(n, ymax))) + \
list(zip(np.full(n, xmax), np.linspace(ymax, ymin, n))) + \
list(zip(np.linspace(xmax, xmin, n), np.full(n, ymin))) + \
list(zip(np.full(n, xmin), np.linspace(ymin, ymax, n)))
)
ax.set_boundary(aoi, transform=ccrs.PlateCarree())
# Plot Ocean Borders
ocean = cf.NaturalEarthFeature('physical', 'ocean', scale='50m', edgecolor='k', facecolor='lightblue', lw=1,
linestyle='-')
ax.add_feature(ocean)
# Colored Land Background
land = cf.NaturalEarthFeature('physical', 'land', scale='50m', facecolor='snow', lw=1, linestyle='--')
ax.add_feature(land)
ax.set_extent([xmin, xmax, ymin, ymax], crs=ccrs.PlateCarree())
# Set gridlines to variable so you can manipulate them
gl = ax.gridlines(draw_labels=True, crs=ccrs.PlateCarree(), x_inline=False, y_inline=False)
gl.xlocator = mticker.FixedLocator([-160, -150, -140, -130, -120])
gl.ylocator = mticker.FixedLocator([50, 55, 60, 65, 70])
gl.top_labels = False
gl.right_labels = False
plt.show()
这就是我所得到的:
我怀疑这与使用ax.set_boundary()
制作 map 有关,但在网上查看后,我找不到任何东西,除了这GitHub issue提到这个问题,但它是关闭的,所以我想他们修复了它.我正在使用Cartopy版本0.21.1.
这个问题是在研究另一个SO问题时产生的:Cartopy labels not appearing for high-latitude non-rectangular projection(所有代码积分到@kbiegseismic).