1

I am using an xarray data and matplotlib to plot it before export

This is the xarr data used

<xarray.DataArray 't2m' (latitude: 361, longitude: 720)>
array([[273.9, 273.9, 273.9, ..., 273.9, 273.9, 273.9],
       [274.1, 274.1, 274.1, ..., 274.1, 274.1, 274.1],
       [274.5, 274.5, 274.5, ..., 274.5, 274.5, 274.5],
       ...,
       [220.6, 220.6, 220.6, ..., 220.6, 220.6, 220.6],
       [221.6, 221.6, 221.6, ..., 221.6, 221.6, 221.6],
       [223. , 223. , 223. , ..., 223. , 223. , 223. ]], dtype=float32)
Coordinates:
  * latitude    (latitude) float64 90.0 89.5 89.0 88.5 ... -89.0 -89.5 -90.0
  * longitude   (longitude) float64 -180.0 -179.5 -179.0 ... 178.5 179.0 179.5
    step        timedelta64[ns] 03:00:00
    valid_time  datetime64[ns] 2020-09-14T03:00:00
Attributes:
    standard_name:  air_temperature

The longitude range is from -180 to +180. If I use the below data with projections the image produced is correct.

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


imgDpi = 100
fig = plt.figure(figsize=(512/imgDpi, 512/imgDpi), dpi=imgDpi) #to convert from inches to px
ax = fig.add_subplot(1,1,1, projection=ccrs.epsg(3857))
ax.imshow(xarr, transform=ccrs.PlateCarree(), origin='upper', cmap='viridis') 
ax.axis('off')
fig.tight_layout(pad=0)
plt.show()
fig.savefig('unsliced.png', format="png", transparent=True, dpi=imgDpi)

image produced using unsliced data

But if I slice the data into four quadrants and plot, there is an issue with projection

topLeft = xarr.sel(longitude=slice(-180, 0), latitude=slice(90, 0))
topRight = xarr.sel(longitude=slice(0, 180), latitude=slice(90, 0))
bottomLeft = xarr.sel(longitude=slice(-180, 0), latitude=slice(0, -90))
bottomRight = xarr.sel(longitude=slice(0, 180), latitude=slice(0, -90))

axTL = fig.add_subplot(2,2,1, projection=ccrs.epsg(3857))
axTL.imshow(topLeft, transform=ccrs.PlateCarree(), origin='upper', cmap='viridis') 
axTL.axis('off')

axTR = fig.add_subplot(2,2,2, projection=ccrs.epsg(3857))
axTR.imshow(topRight, transform=ccrs.PlateCarree(), origin='upper', cmap='viridis')
axTR.axis('off')

axBL = fig.add_subplot(2,2,3, projection=ccrs.epsg(3857))
axBL.imshow(bottomLeft, transform=ccrs.PlateCarree(), origin='upper', cmap='viridis')
axBL.axis('off')

axBR = fig.add_subplot(2,2,4, projection=ccrs.epsg(3857))
axBR.imshow(bottomRight, transform=ccrs.PlateCarree(), origin='upper', cmap='viridis')
axBR.axis('off')

Sliced data

0

I applied Global ccrs and set the min-max for cmap along with extent.

globe_w = ccrs.Globe(datum="WGS84",ellipse="WGS84") 
ax1 = fig.add_subplot(1,1,1, projection=ccrs.PlateCarree(globe=globe_w))
ax1.imshow(data1, transform=ccrs.PlateCarree(globe=globe_w), origin='upper', cmap='viridis', vmin=minTemp, vmax=maxTemp, extent=(-180, 180, 90, -90))
ax1.axis('off')
ax1.set_aspect(2)

Global CCRS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.