Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong plot on basemap with latlon=True #3404

Closed
fph opened this issue Aug 25, 2014 · 3 comments
Closed

Wrong plot on basemap with latlon=True #3404

fph opened this issue Aug 25, 2014 · 3 comments
Assignees
Milestone

Comments

@fph
Copy link

fph commented Aug 25, 2014

There is a bug with point shifting when using latlon=True in Basemap.plot(), as discussed on http://stackoverflow.com/questions/25471723/plotting-on-a-basemap-unexpected-result/25472915: for instance, see the following code

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

m = Basemap(projection='merc',llcrnrlat=-80,urcrnrlat=80,\
            llcrnrlon=-180,urcrnrlon=180,lat_ts=20,resolution='l')
m.drawparallels(np.arange(-90.,91.,30.))
m.drawmeridians(np.arange(-180.,181.,60.))

lon=[
 -44.897539694478894,
 -79.56264363246461,
 -108.31264586027467,
 -129.5832433799378,
 -149.11755440233293,
 173.04624586158417,
 57.26114485166647,
 26.06650557322952,
 6.8910540489469785,
 -15.059586144625898]

lat=[
 -23.30021206811055,
 -22.174848810053106,
 -6.169632450760373,
 18.199421172044598,
 45.95724594253466,
 72.89364342463014,
 69.39230460744983,
 41.88542137864501,
 14.50656439517308,
 -8.974170076274387]

m.plot(lon, lat, 'ro', markersize=14, mec='none', latlon=True)
m.plot(lon[:-1], lat[:-1], 'bo', markersize=10, mec='none', latlon=True)
m.plot(lon[1:], lat[1:], 'go', markersize=6, mec='none', latlon=True)

Output:
2pwkx

The red points should all coincide with the blue and green ones, but they don't.

@tacaswell
Copy link
Member

From the user DrV at SO:

Update: I think I found the bug. The plot method of Basemap first shifts the data so that it starts from the edge of the plot. For example:

In [27]: m.shiftdata(lon)
Out[27]: 
array([ 173.04624586,   57.26114485,   26.06650557,    6.89105405,
        -15.05958614,  -44.89753969,  -79.56264363, -108.31264586,
       -129.58324338, -149.1175544 ])

This is quite ok, as now lines will be contiguous. Unfortunately, the latitude data is not shifted, and the results are exactly what is shown above.

If you shift both latitudes and longitudes by:

lons, lats = m.shiftdata(lon, lat)

and use the shifted version to plot the data, everything is fine.

To my eye it seems that there is some hassle with the decorator _transform1d used around plot and scatter methods. Monkey-patching this (init.py, lines 3239 and 3277 in today's git) by changing the decorator into _transform should help, but it may break other functionality in plot and scatter.

I think the best solution is to sort the data before plotting by using shiftdata as above. (And of course to file a bug report.)

@tacaswell tacaswell added this to the v1.4.x milestone Aug 25, 2014
@pelson
Copy link
Member

pelson commented Aug 26, 2014

@tacaswell - is this not a basemap bug? If so, we should really put this on https://github.com/matplotlib/basemap...

@tacaswell
Copy link
Member

@pelson I suspected so.

Migrated to : matplotlib/basemap#163

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants