简体   繁体   English

无法从 .netcdf 文件中绘制箭袋

[英]Trouble plotting quivers from netcdf file

I am trying to plot wind quivers from a NetCDF file, however, I can only plot one line of quivers, straight across the base map, as seen in the image.我正在尝试从 NetCDF 文件 plot 风箭袋,但是,我只能 plot 一行箭袋,直接穿过底部 map,如图所示。 The code is below.代码如下。 Thank you very much for any help:)非常感谢您的帮助:)

data is here, please replace with the onedrive folder, thanks https://drive.google.com/file/d/160121aFx0Ys6G1jdQZOCT2Ve9eZgOyUy/view?usp=sharing数据在这里,请替换为onedrive文件夹,谢谢https://drive.google.com/file/d/160121aFx0Ys6G1jdQZOCT2Ve9eZgOyUy/view?usp=sharing

import xarray as xr
import cartopy.crs as ccrs
import matplotlib.pyplot as plt

data = xr.open_dataset(<Insert google drive file data here>)

data = data.sel(time='2010-04-14T00:00:00.000000000')

X = data.longitude; Y = data.latitude
U = data.u10[200]; V = data.v10[200]

plt.figure()
ax = plt.subplot(111,projection=ccrs.PlateCarree())

ax.quiver(X[::5], Y[::5], U[::5], V[::5],color='green')

plt.show()

I would expect all the quivers to be plotted, so the graph should be full of the green arrows我希望所有箭袋都被绘制出来,所以图表应该充满绿色箭头

Currently, this is the plotted image:目前,这是绘制的图像:

只绘制了一行数据?

You are only taking data from the last row with data.u10[200].您仅使用 data.u10[200] 从最后一行获取数据。 Instead for the quiver, make coordinates as 2D arrays and plot for instance every 5 point of the dataset.对于箭袋,将坐标设为 2D arrays 和 plot,例如数据集的每 5 个点。 Here is my solution, I downloaded and saved your data as "exdata.nc".这是我的解决方案,我下载了您的数据并将其保存为“exdata.nc”。

#!/usr/bin/env ipython
# --------------------
import xarray as xr
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import numpy as np
# --------------------------------------------------------------------
data = xr.open_dataset('exdata.nc')

data = data.sel(time='2010-04-14T00:00:00.000000000')

X = data.longitude; Y = data.latitude
# --------------------------------------------------------------------
XM,YM = np.meshgrid(X,Y)
U = data.u10; V = data.v10
skipx, skipy = 5,5
# ----------------------------------------------------------------
plt.figure(figsize=(12,12))
ax = plt.subplot(111,projection=ccrs.PlateCarree())

ax.quiver(XM[::skipy,::skipx], YM[::skipy,::skipx], U[::skipy,::skipx], V[::skipy,::skipx],color='green')
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.OCEAN)
plt.show()
# ---------------------------------

Hope this helps as an example!希望这有助于举个例子!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM