Open Kuhron opened 4 years ago
@Kuhron Hey, have you found any solution to this issue? I'm having the same problem.
@chengdang Nope, I just stopped using Basemap altogether. Instead I wrote my own code to do the triangulation for equirectangular projection. Here is the relevant code, if you want to use parts of it:
import matplotlib.pyplot as plt
import matplotlib.tri as tri # interpolation of irregularly spaced data
x, y = lons_deg, lats_deg # actual data
z = vals
# how many x/y to put on rectangle projection
n_grid_x = 1000
n_grid_y = 500
xi = np.linspace(-180, 180, n_grid_x)
yi = np.linspace(-90, 90, n_grid_y)
triang = tri.Triangulation(x, y)
interpolator = tri.LinearTriInterpolator(triang, z)
Xi, Yi = np.meshgrid(xi, yi)
zi = interpolator(Xi, Yi)
MC = plt.contourf(xi, yi, zi, levels=contourf_levels, cmap=cmap)
clb = plt.colorbar(MC, ax=plt.gca()) # without these args, it will say it can't find a mappable object for colorbar
if contour_lines:
plt.contour(xi, yi, zi, levels=contour_line_levels, linewidths=0.5, colors='k')
clb.ax.set_title(key_str)
I ran into this problem while trying to plot interpolated data NOT on a regular latlon grid. Orthographic projection works but cylindrical does not.
Relevant code:
Note that
lats_deg
,lons_deg
, andvals
are 1d np arrays with irregular point spacing (no meshgrid). I usedtri=True
to allow interpolation. This works fine on orthographic projection. But with cylindrical I get the following error:Looking at the relevant file, the docstring for
shiftdata
says "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."So should it not be being called with
tri=True
? Sorry if I have misunderstood something, let me know. Thanks!