Closed
Description
Problem
I have a subset of data that I would like to plot on a global projection (such as mollweide). This works with GMT, but pygmt provides incorrect output.
Example
Let's create a global dataset of random numbers on a grid with 1 degree spacing in latitude and longitude:
lats = np.arange(90., -91., -1.)
lons = np.arange(0., 361., 1.)
data = np.random.rand(181, 361)
da = xr.DataArray(data, coords=[('latitude', lats), ('longitude', lons)])
Now let's plot only the region from 90N-30S and 0E-220E with a Mollweide projection centered on 180 E
figure = pygmt.Figure()
pygmt.makecpt(series=[0., 1., 0.1], cmap='vik', continuous=True)
figure.grdimage(da[0:121, 0:221], region='g', projection='W180/8i', frame=True)
figure.show(method='external')
This is as expected, but now do the same, but centered on 0 E
figure = pygmt.Figure()
pygmt.makecpt(series=[0., 1., 0.1], cmap='vik', continuous=True)
figure.grdimage(da[0:121, 0:221], region='g', projection='W0/8i', frame=True)
figure.show(method='external')
And as a second example, here I want to plot the global data, but using a dataset the doesn't contain the redundant data at 360 E
figure = pygmt.Figure()
pygmt.makecpt(series=[0., 1., 0.1], cmap='vik', continuous=True)
figure.grdimage(da[0:181, 0:360], region='g', projection='W0/8i', frame=True)
figure.show(method='external')
This is a complete failure, but changing the central meridian to 180 degrees works!
figure = pygmt.Figure()
pygmt.makecpt(series=[0., 1., 0.1], cmap='vik', continuous=True)
figure.grdimage(da[0:181, 0:360], region='g', projection='W180/8i', frame=True)
figure.show(method='external')