naught101
naught101

Reputation: 19563

How to wrap data on a basemap plot?

I have an xarray DataArray that goes from 0 to 360 longitude, and -90 to 90 latitude. if I plot it with m.imshow, without specifying the latitudes, the data is offset from the map by 180 degrees:

m = Basemap()
m.drawcoastlines()
m.imshow(mean['Qle'].T)

basemap with offset imshow

or I can do it with m.pcolormesh(x=mean.lon, y=mean.lat, data=mean['Qle'].T), and I get this:

basemap with non-wrapping pcolormesh

What is the best way to wrap the data? I still want the default map layout, with Africa in the middle.

Upvotes: 2

Views: 1126

Answers (1)

naught101
naught101

Reputation: 19563

Ah, found it. pcolormesh has a latlon argument that automatically shifts the data:

m.pcolormesh(x=mean.lon, y=mean.lat, data=mean['Qle'].T, latlon=True)

pcolormesh with shifted data

Upvotes: 3

Related Questions