Open jakevdp opened 11 years ago
Here is a small workaround for you:
from mpl_toolkits import basemap
from matplotlib.lines import Line2D
import matplotlib.pyplot as plt
m1 = basemap.Basemap(projection='cea', lon_0=0)
m1.drawcoastlines()
lon = [-135, -45, 45, 135]
lat = [45, 45, 45, 45]
x, y = m1(lon[:2], lat[:2])
ax = plt.gca()
ax.plot(*m1(lon[:2], lat[:2]))
This way (without latlon=True) the problematic function is not called... Probably latlon=True is there only for large arrays, and I suppose ideally even uniform..
Cheers
Actually this also works fine:
from mpl_toolkits import basemap
m1 = basemap.Basemap(projection='cea', lon_0=0)
m1.drawcoastlines()
lon = [-135, -45, 45, 135]
lat = [45, 45, 45, 45]
m1.plot(*m1(lon[:2], lat[:2]))
I think a good fix would be to check the latlon=True and the length of the arrays and throw an exception if the length is less than 3, with an explanation like: latlon=True is only for uniform grids with lots of points...
Is latlon=True
really only for a uniform grid? I've been using it pretty regularly for any input – I assumed that it basically means "call m(x, y) automatically", and it seems to act that way for arrays longer than 2 elements.
Actually it is also calling shiftdata and the shiftdata is kind of limited, here is the doc to shiftdata:
def shiftdata(self,lonsin,datain=None,lon_0=None):
""" Shift longitudes
(and optionally data) so that they match map projection region. Only valid
for cylindrical/pseudo-cylindrical global projections and data on regular
lat/lon grids. longitudes and data can be 1-d or 2-d, if 2-d it is assumed
longitudes are 2nd (rightmost) dimension.
"""
It actually might work for nonuniform grids, but I am not sure if it is bulletproof...
Duplicating the code here, I could not make it highlighted above, probably because I sent it using email...
def shiftdata(self,lonsin,datain=None,lon_0=None):
""" Shift longitudes
(and optionally data) so that they match map projection region. Only valid
for cylindrical/pseudo-cylindrical global projections and data on regular
lat/lon grids. longitudes and data can be 1-d or 2-d, if 2-d it is assumed
longitudes are 2nd (rightmost) dimension.
"""
I am pretty sure that shiftdata is not needed for scatter, so I've created a PR for that, but I am not sure about plot though...
You need it for plot so that a path drawn around over the pacific doesn't look like it crosses the Atlantic, for example.
On Thu, Aug 27, 2015 at 3:20 PM, Huziy Oleksandr (Sasha) < notifications@github.com> wrote:
I am pretty sure that shiftdata is not needed for scatter, so I've created a PR for that, but I am not too sure about plot though...
— Reply to this email directly or view it on GitHub https://github.com/matplotlib/basemap/issues/126#issuecomment-135528647.
We have also encountered issues using latlon=True
and I'm wondering if it wouldn't hurt to tighten up the documentation to note some of these complexities with its use. It appears a better practice to not use it if possible. However, for someone just starting to use basemap, it is very appealing and further instructions on its usage would be helpful to avoid the issues we were having in https://github.com/MPAS-Dev/geometric_features/issues/14.
Using the following setup, Python 2.7/matplotlib 1.2.1/basemap 1.0.6
If I then run the following command, the line plots as expected:
But plotting just the first two points alone gives a failure:
Here's the result:
Edit: here's an error from a similar call, but I believe it's unrelated to the first:
error: