Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
since version 1.0.6
-------------------
* fix warpimage with projection = 'hammer' (issue 100).

version 1.0.6 (git tag v1.0.6rel)
--------------------------------
* fix drawcounties for Python 3.3.
Expand Down
13 changes: 13 additions & 0 deletions examples/warpimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
plt.title("Blue Marble image warped from 'cyl' to 'mbtfpq' projection",fontsize=12)
print('warp to McBryde-Thomas Flat-Polar Quartic map ...')

# create new figure
fig=plt.figure()
# define projection centered on North America.
m = Basemap(projection='hammer',lon_0=-100,resolution='l')
m.bluemarble(scale=0.5)
# draw coastlines.
m.drawcoastlines(linewidth=0.5,color='0.5')
# draw lat/lon grid lines every 30 degrees.
m.drawmeridians(np.arange(0,360,60),color='0.5')
m.drawparallels(np.arange(-90,90,30),color='0.5')
plt.title("Blue Marble image warped from 'cyl' to 'hammer' projection",fontsize=12)
print('warp to Hammer map ...')

# create new figure
fig=plt.figure()
# define cylindrical equidistant projection.
Expand Down
12 changes: 11 additions & 1 deletion lib/mpl_toolkits/basemap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3982,6 +3982,9 @@ def warpimage(self,image="bluemarble",scale=None,**kwargs):
except ImportError:
raise ImportError('warpimage method requires PIL (http://www.pythonware.com/products/pil)')
from matplotlib.image import pil_to_array
if self.celestial:
msg='warpimage does not work in celestial coordinates'
raise ValueError(msg)
ax = kwargs.pop('ax', None) or self._check_ax()
# default image file is blue marble next generation
# from NASA (http://visibleearth.nasa.gov).
Expand Down Expand Up @@ -4089,7 +4092,8 @@ def warpimage(self,image="bluemarble",scale=None,**kwargs):
# make points outside projection limb transparent.
self._bm_rgba_warped = self._bm_rgba_warped.filled(0.)
# treat pseudo-cyl projections such as mollweide, robinson and sinusoidal.
elif self.projection in _pseudocyl:
elif self.projection in _pseudocyl and \
self.projection != 'hammer':
lonsr,latsr = self(x,y,inverse=True)
mask = ma.zeros((ny,nx,4),np.int8)
lon_0 = self.projparams['lon_0']
Expand All @@ -4112,6 +4116,12 @@ def warpimage(self,image="bluemarble",scale=None,**kwargs):
self._bm_rgba_warped = self._bm_rgba_warped.filled(0.)
# plot warped rgba image.
im = self.imshow(self._bm_rgba_warped,ax=ax,**kwargs)
# for hammer projection, use clip path defined by
# projection limb (patch created in drawmapboundary).
if self.projection == 'hammer':
if not self._mapboundarydrawn:
self.drawmapboundary(color='none',linewidth=None)
im.set_clip_path(self._mapboundarydrawn)
else:
# bmproj True, no interpolation necessary.
im = self.imshow(self._bm_rgba,ax=ax,**kwargs)
Expand Down