Skip to content

CEA projection: plotting all the data works, plotting part of the data fails. #126

@jakevdp

Description

@jakevdp

Using the following setup, Python 2.7/matplotlib 1.2.1/basemap 1.0.6

from mpl_toolkits import basemap

m1 = basemap.Basemap(projection='cea', lon_0=0)
lon = [-135, -45, 45, 135]
lat = [45, 45, 45, 45]

If I then run the following command, the line plots as expected:

m1.plot(lon, lat, latlon=True)

But plotting just the first two points alone gives a failure:

m1.plot(lon[:2], lat[:2], latlon=True)

Here's the result:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-273-c6f75eb64ab8> in <module>()
      8 lat = [45, 45, 45, 45]
      9 #m1.plot(lon, lat, latlon=True)
---> 10 m1.plot(lon[:2], lat[:2], latlon=True)

/Users/jakevdp/anaconda/python.app/Contents/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.pyc in with_transform(self, x, y, *args, **kwargs)
    525             if self.projection in _cylproj or self.projection in _pseudocyl:
    526                 if x.ndim == 1:
--> 527                     x = self.shiftdata(x)
    528                 elif x.ndim == 0:
    529                     if x > 180:

/Users/jakevdp/anaconda/python.app/Contents/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.pyc in shiftdata(self, lonsin, datain, lon_0)
   4700             londiff = np.abs(lonsin[0:-1]-lonsin[1:])
   4701             londiff_sort = np.sort(londiff)
-> 4702             thresh = 360.-londiff_sort[-2]
   4703             itemindex = len(lonsin)-np.where(londiff>=thresh)[0]
   4704             if itemindex:

IndexError: index -2 is out of bounds for axis 0 with size 1

Edit: here's an error from a similar call, but I believe it's unrelated to the first:

lat = [-45, 45, 45, 45, 45, 0]
lon = [135, -135, -45, 45, 135, -90]
m1.plot(lon, lat, latlon=True)

error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-295-d815d338a0b6> in <module>()
     11 lon = [135, -135, -45, 45, 135, -90]
     12 
---> 13 m1.plot(lon, lat, latlon=True)
     14 

/Users/jakevdp/anaconda/python.app/Contents/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.pyc in with_transform(self, x, y, *args, **kwargs)
    525             if self.projection in _cylproj or self.projection in _pseudocyl:
    526                 if x.ndim == 1:
--> 527                     x = self.shiftdata(x)
    528                 elif x.ndim == 0:
    529                     if x > 180:

/Users/jakevdp/anaconda/python.app/Contents/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.pyc in shiftdata(self, lonsin, datain, lon_0)
   4702             thresh = 360.-londiff_sort[-2]
   4703             itemindex = len(lonsin)-np.where(londiff>=thresh)[0]
-> 4704             if itemindex:
   4705                 # check to see if cyclic (wraparound) point included
   4706                 # if so, remove it.

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

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