【问题标题】:Basemap Overlay on Contour/Quiver Plot Python等高线/颤动图 Python 上的底图叠加
【发布时间】:2016-05-28 11:27:14
【问题描述】:

我正在尝试使用我的等高线/箭袋图绘制底图。我下面的代码没有错误,但图像显示不正确;只显示箭筒。有什么帮助吗?

import netCDF4
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import pylab
from mpl_toolkits.basemap import Basemap

ncfile = netCDF4.Dataset('30JUNE2012_0400UTC.cdf', 'r')
dbZ = ncfile.variables['MAXDBZF']
u = ncfile.variables['UNEW']
v = ncfile.variables['VNEW']
print u
print v
print dbZ

data = dbZ[0,0]

data.shape 

print data.shape


z_index = 0  #  z-level you want to plot (0-19)
U = u[0,z_index, :,:] #[time,z,x,y]
V = v[0,z_index, :,:]

map = Basemap(projection = 'merc',llcrnrlat=36,urcrnrlat=40,\
llcrnrlon=-80,urcrnrlon=-74,lat_ts=20,resolution='i')
x = np.arange(0,150)
y = np.arange(0,150)

X,Y = np.meshgrid(x,y)
lon, lat = map(X,Y, inverse = True)

levels = np.arange(5,60,3)
c = plt.contourf(lon,lat,data, levels, cmap='jet')
plt.colorbar()
plt.hold(True)
q=plt.quiver(U,V,width=0.002, scale_units='xy',scale=10)  
qk= plt.quiverkey (q,0.95, 1.02, 20, '20m/s', labelpos='N')
plt.xlim([0,120])

plt.ylim([0,120])


plt.xlabel('X')
plt.ylabel('Y')
plt.title('Reflectivity and Dual-Doppler Winds at 1 KM', fontsize=12)
plt.show()

Here is my data structure:
<type 'netCDF4.Variable'>
float32 UNEW(time, z, y, x)
    missing_value: -32768.0
unlimited dimensions: time
current shape = (1, 20, 150, 150)
filling off

<type 'netCDF4.Variable'>
float32 VNEW(time, z, y, x)
    missing_value: -32768.0
unlimited dimensions: time
current shape = (1, 20, 150, 150)
filling off

<type 'netCDF4.Variable'>
float32 MAXDBZF(time, z, y, x)
    missing_value: -32768.0
unlimited dimensions: time
current shape = (1, 20, 150, 150)
filling off

图像看起来像:

【问题讨论】:

  • 您在这里对纬度/经度有些混淆,您使用 0-150 的范围来表示 y,这在纬度范围从 -90 到 90 的上下文中没有意义。您的 netCDF文件包含 x 和 y 维度的 lat/lon 的显式声明?
  • 是的,文件中只有 1 个点。纬度 = 38.97 和经度 = -77.47 @daryl

标签: python matplotlib plot matplotlib-basemap


【解决方案1】:

您还需要将 lon,lat 添加到您的箭袋中,否则它将以其他轴比例绘制。 您使用的 lat, lon 没有任何意义(正如@daryl 在 cmets 中所说)。 根据您的地图投影,我建议如下:

lonmin = -80
lonmax = -74
latmin = 36
latmax = 40

m = Basemap(projection = 'merc',llcrnrlat=latmin,urcrnrlat=latmax, llcrnrlon=lonmin,urcrnrlon=lonmax,lat_ts=20,resolution='i')

#you should avoid using "map" since its a build-in function.

x = np.arange(lonmin,lonmax,(lonmax-lonmin)/float(U.shape[2]))
y = np.arange(latmin,latmax,(latmax-latmin)/float(U.shape[1]))

X,Y = np.meshgrid(x,y)
lon, lat = m(X,Y)

然后:

c = plt.contourf(lon,lat,data, levels, cmap='jet')
plt.colorbar(c)

q=plt.quiver(lon,lat,U,V,width=0.002, scale_units='xy',scale=10)  
qk= plt.quiverkey (q,0.95, 1.02, 20, '20m/s', labelpos='N')

plt.xlim([lon[0,0],lon[-1,-1]])
plt.ylim([lat[0,0],lat[-1,-1]])

plt.xlabel('X')
plt.ylabel('Y')
plt.title('Reflectivity and Dual-Doppler Winds at 1 KM', fontsize=12)
plt.show()

【讨论】:

    猜你喜欢
    • 2023-02-04
    • 2015-01-08
    • 1970-01-01
    • 2021-12-21
    • 2018-11-19
    • 2017-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多