Hi!
Using this code
import xarray as xr
import numpy as np
import scipy.io
import pygmt
import pickle
import math
import itertools
import matplotlib.pyplot as plt
mat = scipy.io.loadmat('lat_lon.mat')
lat = mat['lat'].flatten()
lon = mat['lon'].flatten()
pygmt.makecpt(cmap="jet", series=[0, 15, 0.1], output="t.cpt")
for i in range(1, 2):
file = 'MSL_eu_%d.mat' % (i)
file2 = 'gng_BMUs_%d_9.mat' % (i)
mat = scipy.io.loadmat(file)
mat2 = scipy.io.loadmat(file2)
fig = pygmt.Figure()
with fig.subplot(nrows=5, ncols=2, figsize=("55c", "25c"), margins=["2c", "18c"]):
for j in range(1, 5):
with fig.set_panel(panel = (j-1)):
name = 'MSL_BMU%d' % (j)
name2 = 'BMU%d' % (j)
tlak = mat[name]
uv = mat2[name2].flatten()
ang = np.arctan2(uv[uv.size//2 : ], uv[ : uv.size//2 ])
ang = ang * 180/math.pi
w = np.sqrt(uv[uv.size//2 : ]**2 + uv[ : uv.size//2 ]**2)
ang = ang.reshape(1, -1)
w = w.reshape(1, -1 )
test = np.array(np.meshgrid(lat,lon)).T.reshape(-1,2)
test = np.hstack((test, ang.T))
test = np.hstack((test, w.T))
test = test[::16]
w = w.reshape((lat.size, lon.size))
ds = xr.DataArray(data = w, dims = ['lat', 'lon'], coords = {'lat': lat, 'lon': lon})
ds2 = xr.DataArray(data = tlak/100, dims = ['lat', 'lon'], coords = {'lat': lat, 'lon': lon})
fig.grdimage(
grid=ds,
projection="Q20c",
cmap="t.cpt",
frame=["a", "+tBMU1"])
fig.coast(
region = [lon.min(),lon.max(),lat.min(),lat.max()],
shorelines="1.p,black")#,
#frame=True)
style = "v0.1c+e,blue"
fig.plot(x = test[:,1], y = test[:,0], style=style, pen = "1p,blue", direction=[test[:,2], test[:,3]/20])
fig.grdcontour(grid = ds2,
interval = 2,
annotation = "2+f15p",
pen="1.5p,red")
if j == 4:
fig.colorbar(cmap="t.cpt", frame=['x+l"Wind speed"', "y+lm/s"])
ime = 'Month_%d.pdf' % (i)
fig.savefig(ime)
I get this image:
Is there a way to make the grdimage fit as it’s supposed to, just like when it first for a single plot?
Thanks!
