matplotlib / basemap

Plot on map projections (with coastlines and political boundaries) using matplotlib
MIT License
775 stars 392 forks source link

pcolormesh not plotting onto 'ortho' basemap #357

Open neillewis96 opened 7 years ago

neillewis96 commented 7 years ago

Hi There,

So I'm really new at this and quite out of my depth.

I was wondering if you could tell me why the following code is just giving me a blank sphere and not one with my pcolormesh information on:


from mpl_toolkits.basemap import Basemap from netCDF4 import Dataset import matplotlib.pyplot as plt import numpy as np

convrain_set = Dataset('proxconvrain30.nc') lats = convrain_set.variables['latitude'][:] lons = convrain_set.variables['longitude'][:] convrain = convrain_set.variables['cvrain'][:] convrain = np.squeeze(convrain) convrain_mean = np.mean(convrain,0)

map = Basemap(projection='ortho',lat_0=45,lon_0=-100,resolution='l')

map.drawmeridians(np.arange(0,360,30)) map.drawparallels(np.arange(-90,90,30))

lon,lat = np.meshgrid(lons,lats)

map.pcolormesh(lon,lat,convrain_mean)

plt.show()


I imagine I've just missed something simple and a little silly...

(Sorry if I've pub this question in the wrong place... I figured the people here were the best placed to help...)

All the best,

Neil

guziy commented 7 years ago

Hi @neillewis96:

you have to convert (lon, lat) to the projection coordinates

xx, yy = map(lon, lat)
map.pcolormesh(xx,yy,convrain_mean)

Cheers

neillewis96 commented 7 years ago

Hi there @guziy,

Thanks for getting back or me... your solution worked.

I'm getting a white line appear on the line lon=0. I imagine this is because my longitude information runs from 1.25 to 358.75 (i.e. not 0 through 360).

I was wondering if this is a common issue (not with the basemap utility, just others' data), and if there is a known solution?

Please find attached an email demonstrating the issue.

screen shot 2017-06-03 at 17 20 36

All the best,

Neil

guziy commented 7 years ago

Hi @neillewis96:

I've tried to reproduce your issue with random data, but it seems to be OK for me... Which version of basemap are you using.

Here is the notebook with my tinkering:

https://github.com/guziy/PyNotebooks/blob/master/basemap_demos/gl_field_0_mer.ipynb

If you want, I could try looking at your data.... You might have undefined values at the poles or smth else.....

Cheers

neillewis96 commented 7 years ago

Hi There @guziy , I'm so sorry for not getting back to you quickly.

I had a look at your tinkering and still have the same problem.

I thought it might be undefined data, but when using the 'kav7' projection I don't seem to have a problem.

Please find attached a zipped .nc file with some data.

Best importing it with:

temp_set = Dataset('precip.nc')
temp = temp_set.variables['precip'][:]
lats = temp_set.variables['latitude'][:]
lons = temp_set.variables['longitude'][:]

Thank-you for your help so far, and sorry for the delay!

Neil precip.nc.zip