basemap
basemap copied to clipboard
Cannot plot a simple map over Africa if lon_0 is not equal to zero
This might be related to https://github.com/matplotlib/basemap/issues/183 I have a quite simple global 0.1 degree image that I would like to put onto a map. The code for reproducing the problem is the following.
m = Basemap(width=12000000, height=8000000,
resolution='l', projection='stere',
lat_ts=0, lat_0=0, lon_0=21.)
# m = Basemap(width=9000000, height=9000000,
# projection='aeqd', lat_0=0, lon_0=1)
lons = np.arange(-179.95, 180.01, 0.1)
lats = np.arange(-89.95, 90.01, 0.1)
data = np.random.random((1800, 3600))
lons, lats = np.meshgrid(lons, lats)
x, y = m(lons, lats)
m.pcolormesh(x, y, data,
latlon=False, cmap='RdBu')
# m.imshow(np.flipud(anom)[1500:2470,600:1200])
m.drawcoastlines()
m.drawcountries()
plt.show()
The result is the following:

Changing lon_0 from 21 to 0 gives the following:

I've also tried this with aeqd and laea projections with the same results.
conda environment for testing
name: test_basemap
channels:
- !!python/unicode
'defaults'
- !!python/unicode
'conda-forge'
dependencies:
- !!python/unicode
'basemap=1.0.7=np112py27_0'
- !!python/unicode
'cairo=1.14.8=0'
- !!python/unicode
'cycler=0.10.0=py27_0'
- !!python/unicode
'dbus=1.10.10=0'
- !!python/unicode
'expat=2.1.0=0'
- !!python/unicode
'fontconfig=2.12.1=3'
- !!python/unicode
'freetype=2.5.5=2'
- !!python/unicode
'functools32=3.2.3.2=py27_0'
- !!python/unicode
'geos=3.5.0=0'
- !!python/unicode
'glib=2.50.2=1'
- !!python/unicode
'gst-plugins-base=1.8.0=0'
- !!python/unicode
'gstreamer=1.8.0=0'
- !!python/unicode
'icu=54.1=0'
- !!python/unicode
'jpeg=9b=0'
- !!python/unicode
'libffi=3.2.1=1'
- !!python/unicode
'libgcc=5.2.0=0'
- !!python/unicode
'libiconv=1.14=0'
- !!python/unicode
'libpng=1.6.27=0'
- !!python/unicode
'libxcb=1.12=1'
- !!python/unicode
'libxml2=2.9.4=0'
- !!python/unicode
'matplotlib=2.0.0=np112py27_0'
- !!python/unicode
'mkl=2017.0.1=0'
- !!python/unicode
'numpy=1.12.1=py27_0'
- !!python/unicode
'openssl=1.0.2k=1'
- !!python/unicode
'pcre=8.39=1'
- !!python/unicode
'pip=9.0.1=py27_1'
- !!python/unicode
'pixman=0.34.0=0'
- !!python/unicode
'pycairo=1.10.0=py27_0'
- !!python/unicode
'pyparsing=2.1.4=py27_0'
- !!python/unicode
'pyqt=5.6.0=py27_2'
- !!python/unicode
'python=2.7.13=0'
- !!python/unicode
'python-dateutil=2.6.0=py27_0'
- !!python/unicode
'pytz=2016.10=py27_0'
- !!python/unicode
'qt=5.6.2=3'
- !!python/unicode
'readline=6.2=2'
- !!python/unicode
'setuptools=27.2.0=py27_0'
- !!python/unicode
'sip=4.18=py27_0'
- !!python/unicode
'six=1.10.0=py27_0'
- !!python/unicode
'sqlite=3.13.0=0'
- !!python/unicode
'subprocess32=3.2.7=py27_0'
- !!python/unicode
'tk=8.5.18=0'
- !!python/unicode
'wheel=0.29.0=py27_0'
- !!python/unicode
'zlib=1.2.8=3'
prefix: !!python/unicode '/home/cpa/.pyenv/versions/miniconda-3.16.0/envs/test_basemap'
confirmed with the latest in master as well.
On Tue, Mar 28, 2017 at 6:05 AM, Christoph Paulik [email protected] wrote:
This might be related to #183 https://github.com/matplotlib/basemap/issues/183 I have a quite simple global 0.1 degree image that I would like to put onto a map. The code for reproducing the problem is the following.
m = Basemap(width=12000000, height=8000000, resolution='l', projection='stere', lat_ts=0, lat_0=0, lon_0=21.) # m = Basemap(width=9000000, height=9000000, # projection='aeqd', lat_0=0, lon_0=1) lons = np.arange(-179.95, 180.01, 0.1) lats = np.arange(-89.95, 90.01, 0.1) data = np.random.random((1800, 3600)) lons, lats = np.meshgrid(lons, lats) x, y = m(lons, lats) m.pcolormesh(x, y, data, latlon=False, cmap='RdBu') # m.imshow(np.flipud(anom)[1500:2470,600:1200]) m.drawcoastlines() m.drawcountries() plt.show()The result is the following: [image: basemap-stere_lon_0 21] https://cloud.githubusercontent.com/assets/380927/24399806/4605b144-13ae-11e7-8917-e4e83936fab5.png
Changing lon_0 from 21 to 0 gives the following: [image: basemap-stere_lon_0 0] https://cloud.githubusercontent.com/assets/380927/24399847/8124229c-13ae-11e7-997f-890206869023.png
I've also tried this with aeqd and laea projections with the same results. conda environment for testing
name: test_basemap channels:
- !!python/unicode 'defaults'
- !!python/unicode 'conda-forge' dependencies:
- !!python/unicode 'basemap=1.0.7=np112py27_0'
- !!python/unicode 'cairo=1.14.8=0'
- !!python/unicode 'cycler=0.10.0=py27_0'
- !!python/unicode 'dbus=1.10.10=0'
- !!python/unicode 'expat=2.1.0=0'
- !!python/unicode 'fontconfig=2.12.1=3'
- !!python/unicode 'freetype=2.5.5=2'
- !!python/unicode 'functools32=3.2.3.2=py27_0'
- !!python/unicode 'geos=3.5.0=0'
- !!python/unicode 'glib=2.50.2=1'
- !!python/unicode 'gst-plugins-base=1.8.0=0'
- !!python/unicode 'gstreamer=1.8.0=0'
- !!python/unicode 'icu=54.1=0'
- !!python/unicode 'jpeg=9b=0'
- !!python/unicode 'libffi=3.2.1=1'
- !!python/unicode 'libgcc=5.2.0=0'
- !!python/unicode 'libiconv=1.14=0'
- !!python/unicode 'libpng=1.6.27=0'
- !!python/unicode 'libxcb=1.12=1'
- !!python/unicode 'libxml2=2.9.4=0'
- !!python/unicode 'matplotlib=2.0.0=np112py27_0'
- !!python/unicode 'mkl=2017.0.1=0'
- !!python/unicode 'numpy=1.12.1=py27_0'
- !!python/unicode 'openssl=1.0.2k=1'
- !!python/unicode 'pcre=8.39=1'
- !!python/unicode 'pip=9.0.1=py27_1'
- !!python/unicode 'pixman=0.34.0=0'
- !!python/unicode 'pycairo=1.10.0=py27_0'
- !!python/unicode 'pyparsing=2.1.4=py27_0'
- !!python/unicode 'pyqt=5.6.0=py27_2'
- !!python/unicode 'python=2.7.13=0'
- !!python/unicode 'python-dateutil=2.6.0=py27_0'
- !!python/unicode 'pytz=2016.10=py27_0'
- !!python/unicode 'qt=5.6.2=3'
- !!python/unicode 'readline=6.2=2'
- !!python/unicode 'setuptools=27.2.0=py27_0'
- !!python/unicode 'sip=4.18=py27_0'
- !!python/unicode 'six=1.10.0=py27_0'
- !!python/unicode 'sqlite=3.13.0=0'
- !!python/unicode 'subprocess32=3.2.7=py27_0'
- !!python/unicode 'tk=8.5.18=0'
- !!python/unicode 'wheel=0.29.0=py27_0'
- !!python/unicode 'zlib=1.2.8=3' prefix: !!python/unicode '/home/cpa/.pyenv/versions/miniconda-3.16.0/envs/test_basemap'
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/matplotlib/basemap/issues/347, or mute the thread https://github.com/notifications/unsubscribe-auth/AARy-I-aw6gPJOPxWXP3NStU1NDzb2erks5rqNtmgaJpZM4MrZrz .
Yes, I get this as well, I'll try look into this...
Hi:
I do not think this is a shiftgrid issue. I think it is the problem with using projection coordinates at the boundaries that leads to having close points in the index space very far in the projection space, and the interpolation (happening in matplotlib) is plotting the values over some parts of the central region. I'll have to investigate it further and think of a good way to try to avoid this.
I do not have a solution yet, but here is a workaround (i.e. mask data outside the basemap view limits):
https://github.com/guziy/PyNotebooks/blob/master/basemap_issue347.ipynb
Cheers
Thanks, The workaround is something I can easily use for now.