@@ -526,7 +526,8 @@ def with_transform(self,x,y,data,*args,**kwargs):
526
526
# shift data to map projection region for
527
527
# cylindrical and pseudo-cylindrical projections.
528
528
if self .projection in _cylproj or self .projection in _pseudocyl :
529
- x , data = self .shiftdata (x , data )
529
+ x , data = self .shiftdata (x , data ,
530
+ fix_wrap_around = plotfunc .__name__ not in ["scatter" ])
530
531
# convert lat/lon coords to map projection coords.
531
532
x , y = self (x ,y )
532
533
return plotfunc (self ,x ,y ,data ,* args ,** kwargs )
@@ -544,7 +545,7 @@ def with_transform(self,x,y,*args,**kwargs):
544
545
# cylindrical and pseudo-cylindrical projections.
545
546
if self .projection in _cylproj or self .projection in _pseudocyl :
546
547
if x .ndim == 1 :
547
- x = self .shiftdata (x )
548
+ x = self .shiftdata (x , fix_wrap_around = plotfunc . __name__ not in [ "scatter" ] )
548
549
elif x .ndim == 0 :
549
550
if x > 180 :
550
551
x = x - 360.
@@ -4723,7 +4724,7 @@ def _ax_plt_from_kw(self, kw):
4723
4724
_ax = plt .gca ()
4724
4725
return _ax , plt
4725
4726
4726
- def shiftdata (self ,lonsin ,datain = None ,lon_0 = None ):
4727
+ def shiftdata (self ,lonsin ,datain = None ,lon_0 = None , fix_wrap_around = True ):
4727
4728
"""
4728
4729
Shift longitudes (and optionally data) so that they match map projection region.
4729
4730
Only valid for cylindrical/pseudo-cylindrical global projections and data
@@ -4746,6 +4747,13 @@ def shiftdata(self,lonsin,datain=None,lon_0=None):
4746
4747
datain original 1-d or 2-d data. Default None.
4747
4748
lon_0 center of map projection region. Defaut None,
4748
4749
given by current map projection.
4750
+ fix_wrap_around if True reindex (if required) longitudes (and data) to
4751
+ avoid jumps caused by remapping of longitudes of
4752
+ points from outside of the [lon_0-180, lon_0+180]
4753
+ interval back into the interval.
4754
+ If False do not reindex longitudes and data, but do
4755
+ make sure that longitudes are in the
4756
+ [lon_0-180, lon_0+180] range.
4749
4757
============== ====================================================
4750
4758
4751
4759
if datain given, returns ``dataout,lonsout`` (data and longitudes shifted to fit in interval
@@ -4784,7 +4792,7 @@ def shiftdata(self,lonsin,datain=None,lon_0=None):
4784
4792
4785
4793
# if no shift necessary, itemindex will be
4786
4794
# empty, so don't do anything
4787
- if itemindex :
4795
+ if fix_wrap_around and itemindex :
4788
4796
# check to see if cyclic (wraparound) point included
4789
4797
# if so, remove it.
4790
4798
if np .abs (lonsin1 [0 ]- lonsin1 [- 1 ]) < 1.e-4 :
@@ -4811,13 +4819,7 @@ def shiftdata(self,lonsin,datain=None,lon_0=None):
4811
4819
datain_save [:,1 :] = datain
4812
4820
datain_save [:,0 ] = datain [:,- 1 ]
4813
4821
datain = datain_save
4814
- # mask points outside
4815
- # map region so they don't wrap back in the domain.
4816
- mask = np .logical_or (lonsin < lon_0 - 180 ,lonsin > lon_0 + 180 )
4817
- lonsin = np .where (mask ,1.e30 ,lonsin )
4818
- if datain is not None and mask .any ():
4819
- # superimpose on existing mask
4820
- datain = ma .masked_where (mask , datain )
4822
+
4821
4823
# 1-d data.
4822
4824
elif lonsin .ndim == 1 :
4823
4825
nlons = len (lonsin )
@@ -4832,7 +4834,7 @@ def shiftdata(self,lonsin,datain=None,lon_0=None):
4832
4834
else :
4833
4835
itemindex = 0
4834
4836
4835
- if itemindex :
4837
+ if fix_wrap_around and itemindex :
4836
4838
# check to see if cyclic (wraparound) point included
4837
4839
# if so, remove it.
4838
4840
if np .abs (lonsin [0 ]- lonsin [- 1 ]) < 1.e-4 :
@@ -4856,12 +4858,14 @@ def shiftdata(self,lonsin,datain=None,lon_0=None):
4856
4858
datain_save [1 :] = datain
4857
4859
datain_save [0 ] = datain [- 1 ]
4858
4860
datain = datain_save
4859
- # mask points outside
4860
- # map region so they don't wrap back in the domain.
4861
- mask = np .logical_or (lonsin < lon_0 - 180 ,lonsin > lon_0 + 180 )
4862
- lonsin = np .where (mask ,1.e30 ,lonsin )
4863
- if datain is not None and mask .any ():
4864
- datain = ma .masked_where (mask , datain )
4861
+
4862
+ # mask points outside
4863
+ # map region so they don't wrap back in the domain.
4864
+ mask = np .logical_or (lonsin < lon_0 - 180 ,lonsin > lon_0 + 180 )
4865
+ lonsin = np .where (mask ,1.e30 ,lonsin )
4866
+ if datain is not None and mask .any ():
4867
+ datain = ma .masked_where (mask , datain )
4868
+
4865
4869
if datain is not None :
4866
4870
return lonsin , datain
4867
4871
else :
0 commit comments