Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basemap warpimage does not handle transparency in non-cylindral projections #5149

Closed
Artax-zanna opened this issue Sep 26, 2015 · 1 comment

Comments

@Artax-zanna
Copy link

Hi,

the situation is the following: I want to do a contourf on top of a background image, added with warpimage. The image is a png with transparent pixels. If the projection is cylindrical everything works fine, but in other projections (I tried only mollweide and robin) the transparency of the background is lost. As result, the plot is completely obscurated by the image.

Here a sample script to reproduce the bug. In the attachments you can find a sample background image.

import matplotlib.pyplot as plt
import numpy as num
from mpl_toolkits.basemap import Basemap

# Background image
img = 'gtrack.png'

# Create longitude/latitude grid
lon_arr = num.arange(-180.0, 181.0, 5.0)
lat_arr = num.arange(-90.0, 91.0, 5.0)
lon, lat = num.meshgrid(lon_arr, lat_arr)

# Create sample data
Z = num.sin(2.0*num.pi*lon/180.0)*num.sin(2.0*num.pi*lat/180.0)

# Plot using cylindrical projection
mp = Basemap(projection='cyl', lon_0=0.0, rsphere=1.0)
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
mp.contourf(lon, lat, Z, ax=ax, latlon=True)
mp.warpimage(image=img, ax=ax, extent=[-180.0, 180.0, -90.0, 90.0],
             aspect='equal', interpolation='none', zorder=2)
ax.set_title('Cylindrical')

# Plot using Mollweide projection
mp = Basemap(projection='moll', lon_0=0.0, rsphere=1.0)
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
mp.contourf(lon, lat, Z, ax=ax, latlon=True)
mp.warpimage(image=img, ax=ax, extent=[-180.0, 180.0, -90.0, 90.0],
             aspect='equal', interpolation='none', zorder=2)
ax.set_title('Mollweide')

# Plot using Hammer projection
mp = Basemap(projection='robin', lon_0=0.0, rsphere=1.0)
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
mp.contourf(lon, lat, Z, ax=ax, latlon=True)
mp.warpimage(image=img, ax=ax, extent=[-180.0, 180.0, -90.0, 90.0],
             aspect='equal', interpolation='none', zorder=2)
ax.set_title('Robin')

gtrack

@tacaswell
Copy link
Member

Moved to basemap issue tracker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants