basemap icon indicating copy to clipboard operation
basemap copied to clipboard

error plotting points that wrap around longitudinal map boundaries in plot() method of Basemap

Open paitor opened this issue 8 years ago • 7 comments

Hi

Using Python 2.7.8 and Basemap 1.0.7 there seems to be a problem plotting points that wrap around longitudinal map boundaries in plot() method of Basemap if the points wrap back and forth. The problem can be avoided by sorting the points by longitude prior plotting (but this does of course not work if plotting a segment based on the points since sorting will screw up the order of the points along the segment)

The following code illustrates the problem by plotting the same three points sorted in different ways (first plot works)

#! /usr/bin/env python

import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

bm = Basemap(llcrnrlon=0,llcrnrlat=-80,urcrnrlon=360,urcrnrlat=80,projection='mill')
fig=plt.figure(figsize=(8,4.5))   

# figure with three points work
bm.plot([-30,-20,10], [10,10,10], "ro", latlon=True)
plt.show()

# figure with less than three points fail
bm.plot([-30,10,-20], [10,10,10], "ro", latlon=True)
plt.show()

and the error running the above code (after closing the first successful plot window) is

:~/SNSN/ALERT/seedlink> python TryBasemap.py 
Traceback (most recent call last):
  File "TryBasemap.py", line 16, in <module>
    bm.plot([-30,10,-20], [10,10,10], latlon=True)
  File "[...]/python2.7/site-packages/mpl_toolkits/basemap/__init__.py", line 536, in with_transform
    x = self.shiftdata(x)
  File "[...]/python2.7/site-packages/mpl_toolkits/basemap/__init__.py", line 4777, in shiftdata
    if itemindex:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

regP

paitor avatar Oct 26 '15 14:10 paitor

Digging into this, once I fixed the "truthiness" problem and added your unit test, it revealed some more bugs under the hood.

This is gonna be a fun rabbit hole!

WeatherGod avatar Oct 28 '15 15:10 WeatherGod

I have created #224 that should partly address the problem. At the very least, it won't error out anymore.

WeatherGod avatar Oct 28 '15 16:10 WeatherGod

Related to #197

guziy avatar Oct 28 '15 16:10 guziy

See also question on Stack Overflow.

gerritholl avatar Mar 17 '16 18:03 gerritholl

#332 has been merged in, but it doesn't fix this particular problem, unfortunately, for the case of plot(). If one does scatter(), then it works, so there appears to be orthogonal issues at play here.

WeatherGod avatar Jan 04 '17 15:01 WeatherGod

Upping this issue since it's been 4 months and I'm still experiencing this issue...

cchaine avatar May 16 '17 09:05 cchaine

Also very interested in a solution to this problem. I need plot and not scatter: I want to draw segments. I also wanted to mention that the problem is still here in release 1.1.

lguez avatar Oct 11 '18 13:10 lguez