Skip to content

Imshow on non rectangular projections e.g. Robinson plots outside of map #175

@cpaulik

Description

@cpaulik

Hi,

You have already addressed this issue a few years ago here where you said it would be better to use pcolor.

In my case I need the possibility of imshow to use a NxMx3 array as input to explicitly set the colors.

An example of the image I get and some code:

fig = plt.figure(figsize=(10, 18))
ax1 = plt.subplot(211)
m = Basemap(projection='robin',
            lon_0=0., ax=ax1)

# Compute lats and lons arrays
lons = (-180. + np.arange(720) / 2.) + 0.25
lats = (-90. + np.arange(360) / 2.) + 0.25

nx = int((m.xmax - m.xmin) / 25000.) + 1
ny = int((m.ymax - m.ymin) / 25000.) + 1

waterf_rp = m.transform_scalar(allf[:, :, 0], lons, lats, nx, ny)
radf_rp = m.transform_scalar(allf[:, :, 1], lons, lats, nx, ny)
tempf_rp = m.transform_scalar(allf[:, :, 2], lons, lats, nx, ny)

allf_rp = np.dstack((waterf_rp, radf_rp, tempf_rp))

# Plot Data
im = m.imshow(np.flipud(allf_rp))

# Add Grid Lines
m.drawparallels(np.arange(-90., 90., 30.), labels=[1, 0, 0, 0], fontsize=10)
m.drawmeridians(np.arange(-180., 180., 60.), labels=[0, 0, 0, 1], fontsize=10)

# Add Coastlines, States, and Country Boundaries
m.drawcoastlines()
m.drawstates()
m.drawcountries()

robinson problem example

I also tried to use the keywords masked and checkbounds in the transform_scalar method but they did not change the result.

It seems you already have a solution for the problem in the warpimage routine since the robinson projections works fine with. e.g. bluemarble ?

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
# setup Lambert Conformal basemap.
# set resolution=None to skip processing of boundary datasets.
m = Basemap(projection='robin',
            lon_0=0.)
m.bluemarble()
plt.show()

bluemarble_robinson

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions