python - 卡托皮米勒投影中纬度标签的奇怪设置
问题描述
只是为了让事情变得简单,我复制了我的问题,从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+
解决方案
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()
推荐阅读
- arrays - 映射时增加或减少反应数组中的值
- javascript - React native, undefined is not an object and handle onChange
- python - 使用 python 更新文件名和路径
- android - 任务“:app:validateSigningRelease”执行失败
- javascript - 国际电话输入中的 jquery 验证错误后,国家/地区代码被附加到字段中
- symfony - 按查询计算分组结果
- javascript - 带退格键并删除
- google-apps-marketplace - 在 Google Marketplace 中发布部分启用的附加组件
- css - 为什么 Safari 浏览器中的边框会被切掉?
- javascript - 自定义登录按钮不保存登录状态