center_longitude中的Cartopy中等高线图中的白线

时间:2019-05-28 18:28:53

标签: 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

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

1 个答案:

答案 0 :(得分:1)

您应该使用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()