matplotlib / basemap

Plot on map projections (with coastlines and political boundaries) using matplotlib
MIT License
779 stars 392 forks source link

Problems with Basemap.scatter #191

Open bjornaa opened 9 years ago

bjornaa commented 9 years ago

Hi,

I have stumbled over a bug in scatter plot. With latlon=True, it crashes with zero, one or two points.

Example code:

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

bmap = Basemap(projection='merc',
               llcrnrlon=9, urcrnrlon=13,
               llcrnrlat=63, urcrnrlat=65,
               resolution='c')

lon = [10.0, 12.0]
lat = [64.0, 65.0]

bmap.scatter(lon, lat, latlon=True)

plt.show()

This crashes with the following Traceback:

Traceback (most recent call last):
  File "a.py", line 12, in <module>
    bmap.scatter(lon, lat, latlon=True)
  File "/opt/anaconda/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.py", line 536, in with_transform
    x = self.shiftdata(x)
  File "/opt/anaconda/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.py", line 4775, in shiftdata
    thresh = 360.-londiff_sort[-2]
IndexError: index -2 is out of bounds for axis 0 with size 1

I am using python 2.7.10, matplotlib 1.4.3, basemap 1.0.7 on a 64-bit Linux machine

pwolfram commented 9 years ago

This may be a similar issue as #126

WeatherGod commented 9 years ago

Once matplotlib 1.5 gets released, I am going to spend some time to fix up basemap and get a new release of it out.

On Thu, Aug 27, 2015 at 10:45 AM, Phillip Wolfram notifications@github.com wrote:

This may be a similar issue as #126 https://github.com/matplotlib/basemap/issues/126

— Reply to this email directly or view it on GitHub https://github.com/matplotlib/basemap/issues/191#issuecomment-135456540.

pwolfram commented 9 years ago

@WeatherGod Ok, sounds good. If you think this is something easy to fix I could try to fix it too. Thanks!

WeatherGod commented 9 years ago

I'd be more than happy to have more eyes on this codebase. I am not all that familiar with it, and it is crufty, so I don't know how easy or hard it would be to fix any particular issue. So, PRs on any aspect of Basemap is welcomed.

One thing keeping me from more actively accepting patches is that TravisCI isn't turned on for Basemap, so I don't know if a patch breaks things or not. That should probably get fixed first.

My plan for Basemap is to put it into maintenance mode. I do not want to do any new developments (although I won't refuse any PRs that adds features), but these bug reports that have been accumulating shows that there is still interest in this project and that it deserves to have things fixed at the least. The intention is that cartopy will take over basemap, but cartopy still needs to mature some more, and basemap has a huge inertia, which will keep it relevant for a while longer.

On Thu, Aug 27, 2015 at 10:57 AM, Phillip Wolfram notifications@github.com wrote:

@WeatherGod https://github.com/WeatherGod Ok, sounds good. If you think this is something easy to fix I could try to fix it too. Thanks!

— Reply to this email directly or view it on GitHub https://github.com/matplotlib/basemap/issues/191#issuecomment-135460274.

pelson commented 9 years ago

The intention is that cartopy will take over basemap, but cartopy still needs to mature some more, and basemap has a huge inertia, which will keep it relevant for a while longer.

I completely agree with this, particularly the inertia part. Basemap has some awesome examples, and for some people, they cover all the bases.

The exception to this is when one starts to get problems with datelines, wrapping, and ill defined geometries. I think Basemap should do what it can to fix these things, within reason, but it is important to remember that Basemap simply does not have enough context to successfully visualise data that has already been badly transformed (normally by the user). The act of xs, ys = m(lons, lats) typically throws away important context about connectivity that cannot be (non-heuristically) fixed. This is the fundamental difference between cartopy and Basemap.