To mitigate the problem described here, I'm trying to draw my pcolor
plot in two complimentary parts. I have X
and Y
data that correspond to longitude and latitude, respectively (in reality, this is translated to projection coordinates by cartopy
, but the problem at hand is independent of that). The longitude may wrap around the antimeridian, which causes quadrangles to be drawn all across the globe. To prevent this, I'm trying to draw the two parts separately, such as illustrated below:
#!/usr/bin/env python3.6
from numpy import array, ma
from matplotlib.pyplot import figure, pcolor, savefig
lons = array([[ 100., 120., 140., 160., 180.],
[ 120., 140., 160., 180., -160.],
[ 140., 160., 180., -160., -140.],
[ 160., 180., -160., -140., -120.],
[ 180., -160., -140., -120., -100.],
[-160., -140., -120., -100., -80.]])
lats = array([[ 0., 10., 20., 30., 40.],
[ 0., 10., 20., 30., 40.],
[ 0., 10., 20., 30., 40.],
[ 0., 10., 20., 30., 40.],
[ 0., 10., 20., 30., 40.],
[ 0., 10., 20., 30., 40.]])
bts = array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24],
[25, 26, 27, 28, 29]])
figure()
pcolor(lons, lats, ma.masked_where(lons>0, bts))
savefig("/tmp/ok.png")
figure()
pcolor(lons, lats, ma.masked_where(lons<0, bts))
savefig("/tmp/not_ok.png")
Now, the plot where I mask all positive longitudes looks more or less as I would expect it to:
but the plot where I mask all negative longitudes, still plots quadrangles all over the axes:
In the second plot, I'd like to draw only quadrangles corresponding to positive longitudes. Why is it still making connections to masked values, and how can I stop this from happening?
See Question&Answers more detail:
os