Hi!
I am trying to plot temperature and wind data from a Xarray data array.
To show what I want to achieve, I have attached an example Matplotlib plot and a GMT plot that somewhat mimics it, here still without the wind vectors. The plot is made with GMT 6.1.1 and pygmt 0.2.0.
I am getting stuck trying to plot the wind vectors.
How should I proceed in pygmt? I tried:
u=ds.u.isel(isobaricInhPa=0)
v=ds.v.isel(isobaricInhPa=0)
fig.plot(lons.values, lats.values, direction=[u.values, v.values], style='V')
which yields:
---------------------------------------------------------------------------
GMTInvalidInput Traceback (most recent call last)
<ipython-input-174-4dd1ef6c1a08> in <module>
36 fig.coast(projection=PROJECTION, region=REGION, frame="g", land="gray")
37 fig.grdimage(windspeed.isel(isobaricInhPa=0), n='b', Q=True)
---> 38 fig.plot(lons.values, lats.values, direction=[u.values, v.values], style='V')
39 fig.coast(projection=PROJECTION, region=REGION, frame="g", shorelines=True)
40 fig.text(position='BL',text='d.', font=label_font)
~/opt/miniconda3/envs/pygmt/lib/python3.6/site-packages/pygmt/helpers/decorators.py in new_module(*args, **kwargs)
235 if alias in kwargs:
236 kwargs[arg] = kwargs.pop(alias)
--> 237 return module_func(*args, **kwargs)
238
239 new_module.aliases = aliases
~/opt/miniconda3/envs/pygmt/lib/python3.6/site-packages/pygmt/helpers/decorators.py in new_module(*args, **kwargs)
372 kwargs[arg] = separators[fmt].join(f"{item}" for item in value)
373 # Execute the original function and return its output
--> 374 return module_func(*args, **kwargs)
375
376 return new_module
~/opt/miniconda3/envs/pygmt/lib/python3.6/site-packages/pygmt/base_plotting.py in plot(self, x, y, data, sizes, direction, **kwargs)
561 )
562
--> 563 with file_context as fname:
564 arg_str = " ".join([fname, build_arg_string(kwargs)])
565 lib.call_module("plot", arg_str)
~/opt/miniconda3/envs/pygmt/lib/python3.6/contextlib.py in __enter__(self)
79 def __enter__(self):
80 try:
---> 81 return next(self.gen)
82 except StopIteration:
83 raise RuntimeError("generator didn't yield") from None
~/opt/miniconda3/envs/pygmt/lib/python3.6/site-packages/pygmt/clib/session.py in virtualfile_from_vectors(self, *vectors)
1160 rows = len(arrays[0])
1161 if not all(len(i) == rows for i in arrays):
-> 1162 raise GMTInvalidInput("All arrays must have same size.")
1163
1164 family = "GMT_IS_DATASET|GMT_VIA_VECTOR"
GMTInvalidInput: All arrays must have same size.
Any help would be greatly appreciated!
Jelle
p.s. the fig.plot()
is part of a larger pygmt call, for context:
label_font = '14p,Helvetica-Bold,black'
REGION = 'g'
PROJECTION = 'G-35/60/8c'
# Figuur D
fig.coast(projection=PROJECTION, region=REGION, frame="g", land="gray")
fig.grdimage(windspeed.isel(isobaricInhPa=0), n='b', Q=True)
fig.plot(lons.values, lats.values, direction=[u.values, v.values], style='V')
fig.coast(projection=PROJECTION, region=REGION, frame="g", shorelines=True)
fig.text(position='BL',text='d.', font=label_font)