简体   繁体   English

卡托皮米勒投影中纬度标签的奇怪设置

[英]Weird setting of latitude labels in cartopy Miller projection

Just to make things easy I have reproduced my problem adapting an example from the gallery of cartopy's latest release只是为了让事情变得简单,我复制了我的问题,从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()

在此处输入图像描述

For some reason the y axis labels are changed and have weird values.由于某种原因,y 轴标签已更改并且具有奇怪的值。 Potentially something that has to do with LatitudeFormatter?可能与 LatitudeFormatter 有关?

Important: For some environment related reasons I'm using cartopy 0.18.0b3.dev15+重要提示:出于某些与环境相关的原因,我使用的是 cartopy 0.18.0b3.dev15+

Cartopy is giving you exactly what you asked for, which is labels at (-90, -60, -30, 0, 30, 60, 90) in the Miller projection , ie not in degrees of latitude. Cartopy 提供的正是您所要求的,即米勒投影中 (-90, -60, -30, 0, 30, 60, 90) 处的标签,即不是纬度。 Because you are using the LatitudeFormatter it is converting these Miller projection points into degrees latitude for you for display.因为您使用的是LatitudeFormatter ,所以它将这些米勒投影点转换为纬度以供您显示。

What it looks like you wanted to do was label in a lat/long coordinate system, so you should use ccrs.PlateCarree() as the crs argument when creating the ticks, like this:看起来您想要做的是 label 在纬度/经度坐标系中,因此您应该在创建刻度时使用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()

带有纬度标签的米勒投影

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM