Python Cartopy轮廓缺少投影
我正试图通过cartopy将一些数据放到轮廓图上。然而,在绘制数据后,投影似乎仍处于关闭状态。 表面温度X和表面温度Y为lat/lon,而遮罩填充为实际数据值。这似乎在basemap中有效,但我不确定为什么在cartopy中无效 卡通:Python Cartopy轮廓缺少投影,python,matplotlib,matplotlib-basemap,cartopy,Python,Matplotlib,Matplotlib Basemap,Cartopy,我正试图通过cartopy将一些数据放到轮廓图上。然而,在绘制数据后,投影似乎仍处于关闭状态。 表面温度X和表面温度Y为lat/lon,而遮罩填充为实际数据值。这似乎在basemap中有效,但我不确定为什么在cartopy中无效 卡通: fig=plt.figure(figsize=(12,4.76),dpi=100) 图clf() ax=plt.轴(投影=ccrs.Mercator()) ax.海岸线() ax.contourf(表面温度X、表面温度Y、表面温度掩蔽填充[:],latlon='
fig=plt.figure(figsize=(12,4.76),dpi=100)
图clf()
ax=plt.轴(投影=ccrs.Mercator())
ax.海岸线()
ax.contourf(表面温度X、表面温度Y、表面温度掩蔽填充[:],latlon='true',transform=ccrs.Mercator())
plt.show()
底图:
fig=plt.figure(figsize=(15,4.76),dpi=100)
图clf()
plt.轴([0,0,1,1],frameon=False)
标题(标题)
m=底图(投影='merc',llcrnrlat=-80,urcrnrlat=80,llcrnrlon=0,urcrnrlon=360,lat=20,分辨率='c')
m、 轮廓F(表面温度X、表面温度Y、表面温度掩模填充[:],latlon=‘真’)
底图结果:
Cartopy结果(轮廓注释掉):
卡通效果(轮廓)
cartopy的范例是始终在lat/lon坐标上工作。这意味着,不应根据投影变换数据,而应保持在lat/lon中
因此
ax.contourf(..., transform = ccrs.Mercator())
你需要
ax.contourf(..., transform = ccrs.PlateCarree())
一个完整的例子:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.examples.waves import sample_data
ax = plt.axes(projection=ccrs.Mercator())
lons, lats, data = sample_data(shape=(20, 40))
ax.contourf(lons, lats, data, transform=ccrs.PlateCarree())
ax.coastlines()
ax.gridlines()
plt.show()