所以这是我的代码:
from netCDF4 import *
import datetime as dt
import numpy as np
import numpy.ma as ma
from datetime import date, datetime, timedelta
import matplotlib.pyplot as plt
nc=Dataset('datasets/essai.nc')
time_var = nc.variables[str('forecast_time0')]
wave_var = nc.variables['DIST_GDS0_SFC']
lat = nc.variables['g0_lat_1'][:]
lon = nc.variables['g0_lon_2'][:]
uin = nc.variables['UOGRD_GDS0_DBSL'][:]
vin = nc.variables['VOGRD_GDS0_DBSL'][:]
plt.quiver(lon[::5], lat[::5], uin[::5], vin[::5], scale=200)
这是我得到的错误:
Traceback (most recent call last):
File "nctry.py", line 37, in <module>
plt.quiver(lon[::5], lat[::5], uin[::5], vin[::5], scale=200)
File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 2877, in quive
r
ret = ax.quiver(*args, **kw)
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 6627, in quiver
q = mquiver.Quiver(self, *args, **kw)
File "C:\Python27\lib\site-packages\matplotlib\quiver.py", line 394, in __init
__
X, Y, U, V, C = _parse_args(*args)
File "C:\Python27\lib\site-packages\matplotlib\quiver.py", line 356, in _parse
_args
nr, nc = U.shape
ValueError: too many values to unpack
我认为问题来自UOGRD和VOGRD,它有很多价值,但不知道如何操纵它?
以下是我的uogrd的样子:
答案 0 :(得分:0)
首先,欢迎访问该网站。也就是说,我认为这个问题在标准StackExchange网站上可能会更好,因为它更多的是关于绘制数据而不是每个人说的GIS。仍然很乐意提供帮助:)
查看quiver plot的文档,我们得到以下信息:
通过你正在进行的切片,你在第一维中的每个数组中得到每5个 th 值。假设lat和lon是单维数组,那么你得到每5 th lat和lon值。由于UOGRD和VOGRD是二维数组,因此您将获得每5 th 列,这意味着您将没有足够的行从您的纬度和经度扩展出来。
要做的事情:
plt.quiver(uin[::5], vin[::5], scale=200)
print lon[::5].shape, lat[::5].shape, uin[::5].shape, vin[::5].shape
plt.quiver(lon[::5], lat[::5], uin[::5, ::5], vin[::5, ::5], scale=200)
希望这有帮助!