python - 在 center_longitude 上的 cartopy 等高线图中的白线

标签 python matplotlib cartopy

我正在用 Cartopy 和 Matplotlib 绘制一些填充轮廓。数据位于纬度/经度网格上,当在 cartopy 投影上绘图时,一条白线从图形中间向下延伸,或者我在 ccrs.PlateCarree() 中设置“central_longitude”的任何位置

这是一个快速设置,显示了我在说什么。使用代码:

    import numpy as np
    import matplotlib.pyplot as plt
    import cartopy.crs as ccrs
    import cartopy.feature as cfeature

    lon = np.arange(0, 360, 1)
    lat = np.arange(-90, 90, 1)

    data = np.zeros((180, 360))

    fig = plt.figure()
    ax = plt.subplot(projection=ccrs.PlateCarree())
    ax.contourf(lon, lat, data)
    ax.add_feature(cfeature.COASTLINE.with_scale('50m'))
    plt.show()

产生图像:
enter image description here

有没有办法去除这条白线?

最佳答案

您应该使用 cartopy.util.add_cyclic_point这样contourf 将数据视为x 方向上的连续数据,白线将消失:

import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.util import add_cyclic_point

lon = np.arange(0, 360, 1)
lat = np.arange(-90, 90, 1)

data = np.zeros((180, 360))

data, lon = add_cyclic_point(data, coord=lon)

fig = plt.figure()
ax = plt.subplot(projection=ccrs.PlateCarree())
ax.contourf(lon, lat, data)
ax.add_feature(cfeature.COASTLINE.with_scale('50m'))
plt.show()

关于python - 在 center_longitude 上的 cartopy 等高线图中的白线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56348136/

相关文章:

python - 如何在单个发布请求中将多个文本字符串发送到谷歌云自然语言API

python - 正则表达式:向后匹配最接近的值

python - 创建和使用模块 "float object not callable"-Python 3.5.1

python - 创建充当校验和并验证发件人的文件的最佳方法?

python - 应用 cartopy 变换时图像倾斜

python - matplotlib中图形的填充范围

python - matplotlib - 沿绘图线更改标记颜色

Python:如何在 twinx 之后制作图例

python - Cartopy 示例产生段错误

python - 在 Linux Ubuntu 18.04 上从 pip 安装 cartopy 退出并出现各种错误