Cartopy:海岸线()和轮廓线f()会干扰

时间:2020-02-06 12:29:49

标签: matplotlib cartopy proj

我正在尝试从底图迁移到Cartopy,并观看演示示例。我有一个同时使用海岸线()和轮廓线()的简单代码。我可以分别获得两个,但不能同时获得。数据集是一个netcdf文件,其中包含西地中海的海表温度数据。代码是:

[
    {
       project: 
       {
            id: "5da94c360a786c9f",
            name: "example",
       },
       taskGroup: "general",
       startDate: "2017-05-09T11:30:00.000Z",
       endDate: "2018-05-10T02:00:00.000Z",
       extendDate: null,
       lastActivity: "2017-08-16T05:00:00.000Z",
       rating: "2",
       _id: "5dd2a884978e9cc0",
       status: "Accepted",
       title: "Other",
       extendList: [ ],
    }
]

使用此代码,我得到:

enter image description here

如果我使用:

[ 
    {
        Id: 1,
        Subject: 'Explosion of Betelgeuse Star',
        Location: 'Space Centre USA',
        StartTime: new Date(2019, 0, 6, 9, 30),
        EndTime: new Date(2019, 0, 6, 11, 0),
        CategoryColor: '#1aaa55'
    }, 
    {
        Id: 2,
        Subject: 'Thule Air Crash Report',
        Location: 'Newyork City',
        StartTime: new Date(2019, 0, 7, 12, 0),
        EndTime: new Date(2019, 0, 7, 14, 0),
        CategoryColor: '#357cd2'
    }
]

我得到一个白色矩形。

如果我使用:

   import numpy as np
   from netCDF4 import Dataset
   import cartopy
   import matplotlib.pyplot as plt

   # DATA
   data = Dataset('20190715.0504.n19.nc','r')
   lon = data.variables['lon'][:]
   lat = data.variables['lat'][:]
   sst = data.variables['mcsst'][0,:,:].squeeze()
   xxT,yyT = np.meshgrid(lon,lat)

   # PLOT
   fig = plt.figure(figsize=(10, 5))
   ax1 = fig.add_axes([0.01,0.01,0.98,0.98],projection=cartopy.crs.Mercator())
   ax1.coastlines()
   #ax1.contourf(xxT,yyT,sst)
   ax1.set_extent([16.5, -15.0, 35.0, 46.5])

   plt.show()

我得到了轮廓数据。

enter image description here

但两者都有:

   #ax1.coastlines()
   ax1.contourf(xxT,yyT,sst)
   ax1.set_extent([16.5, -15.0, 35.0, 46.5])

轮廓没问题!但没有海岸线。如果最后

   #ax1.coastlines()
   ax1.contourf(xxT,yyT,sst)
   ax1.set_extent([16.5,-15.0,35.0,46.5],crs=cartopy.crs.Mercator())

仅显示海岸线,而不显示轮廓!!我尝试了解如何进行处理,因为尝试将其包含在GUI中时,出现了一些问题,这些问题包括选项显示/隐藏涂装线,功能等。以防万一,如果我使用的是Python 3.7.4,Cartopy 0.17,proj4 5.2, matplotlib 3.1.1。谢谢!

1 个答案:

答案 0 :(得分:0)

尽管有了swatchai的建议,但我仍然不明白为什么我需要将 transform 关键字与特定的 PlateCarree 投影关键字一起使用,如果:

fig = plt.figure(figsize=(10, 5))
ax1 = fig.add_axes([0.01, 0.01, 0.98, 0.98],projection=cartopy.crs.Mercator())
ax1.coastlines('10m')
ax1.set_extent([16.5, -15.0, 35.0, 46.5])
ax1.contourf(xxT,yyT,sst,transform=cartopy.crs.PlateCarree())

结果如下: enter image description here