【问题标题】:Cartopy lat/lon gridlines not showing labels on left/right of plotCartopy 纬度/经度网格线未在图的左侧/右侧显示标签
【发布时间】: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


    【解决方案1】:

    我使用 cartopy 版本 0.19.0 并且对网格线的标签没有任何问题。通过对您的代码进行微小的更改,我运行并在所有方面获取网格线的标签。

    对于标注与地图特征冲突导致标注难以阅读的问题,制图师有多种选择来解决这个问题。他们通常使用绘图的颜色和样式。

    修改后的代码和绘图演示了以上所有内容。

    【讨论】:

      猜你喜欢
      • 2021-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-28
      • 1970-01-01
      • 1970-01-01
      • 2019-12-28
      相关资源
      最近更新 更多