【发布时间】:2022-08-24 17:10:14
【问题描述】:
我正在使用以下代码绘制 NorthPolarStereo 地图。我想标记纬度和经度网格线,但 Cartopy 似乎只是将这些标签放在情节的顶部/底部,我希望它们到处走走。由于这个相关的 SO 问题,我知道这样的事情一定是可能的:Setting longitude of latitude tick labels in NorthPolarStereo Cartopy 但我似乎无法重现它。
另外,有没有办法自定义内联 y(纬度)标签的位置?它们被网格线和海岸线特征部分遮挡。
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import numpy as np
import matplotlib.ticker as mticker
from matplotlib.offsetbox import AnchoredText
fig = plt.figure(figsize=(5,5))
projection = ccrs.NorthPolarStereo(central_longitude=-100)
ax = plt.subplot(projection=projection)
ax.set_extent([0, 360, 65, 90], crs=ccrs.PlateCarree())
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.LAND)
xticks = np.arange(-180, 181, 30)
yticks = np.arange(70, 91, 10)
gl = ax.gridlines(crs=ccrs.PlateCarree(), color=\'k\', draw_labels=True, dms=True, x_inline=False, y_inline=True)
gl.ylocator = mticker.FixedLocator(yticks)
gl.xlocator = mticker.FixedLocator(xticks)
gl.xlabel_style = {\'rotation\':0}
text = AnchoredText(\'© Natural Earth; license: public domain\',
loc=4, prop={\'size\': 10}, frameon=True)
ax.add_artist(text)
plt.show()
结果图像:
标签: python matplotlib geospatial cartopy