首页 > 解决方案 > 卡托皮米勒投影中纬度标签的奇怪设置

问题描述

只是为了让事情变得简单,我复制了我的问题,从cartopy 最新版本的画廊中改编了一个例子

fig = plt.figure(figsize=(8, 10))

miller = ccrs.Miller(central_longitude=180)

ax = fig.add_subplot(1, 1, 1, projection=miller)

ax.set_global()
ax.coastlines()
ax.set_yticks(np.arange(-90, 90.5, 30), crs=miller)
lat_formatter = LatitudeFormatter()
ax.yaxis.set_major_formatter(lat_formatter)

plt.show()

在此处输入图像描述

由于某种原因,y 轴标签已更改并且具有奇怪的值。可能与 LatitudeFormatter 有关?

重要提示:出于某些与环境相关的原因,我使用的是 cartopy 0.18.0b3.dev15+

标签: pythoncartopy

解决方案


Cartopy 提供的正是您所要求的,即米勒投影中 (-90, -60, -30, 0, 30, 60, 90) 处的标签,即不是纬度。因为您正在使用LatitudeFormatter它将这些米勒投影点转换为纬度以供您显示。

您想要做的是在纬度/经度坐标系中添加标签,因此您应该在创建刻度时ccrs.PlateCarree()用作参数,如下所示:crs

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.mpl.ticker import LatitudeFormatter
import numpy as np

fig = plt.figure(figsize=(8, 10))

miller = ccrs.Miller(central_longitude=180)

ax = fig.add_subplot(1, 1, 1, projection=miller)

ax.set_global()
ax.coastlines()
ax.set_yticks(np.arange(-90, 90.5, 30), crs=ccrs.PlateCarree())
lat_formatter = LatitudeFormatter()
ax.yaxis.set_major_formatter(lat_formatter)

plt.show()

带有纬度标签的米勒投影


推荐阅读