matplotlib / matplotlib/basemap
error plotting points that wrap around longitudinal map boundaries in plot() method of Basemap
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 817
- Forks
- 395
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the supplied Python script, then inspect mpl_toolkits/basemap/init.py at the plot wrapper and shiftdata method around the reported line. The fix is done when the unsorted [-30, 10, -20] points plot without the ambiguous-array error while preserving their order.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- matplotlib, python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100