@@ -526,7 +526,8 @@ def with_transform(self,x,y,data,*args,**kwargs):
526526 # shift data to map projection region for
527527 # cylindrical and pseudo-cylindrical projections.
528528 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" ])
530531 # convert lat/lon coords to map projection coords.
531532 x , y = self (x ,y )
532533 return plotfunc (self ,x ,y ,data ,* args ,** kwargs )
@@ -544,7 +545,7 @@ def with_transform(self,x,y,*args,**kwargs):
544545 # cylindrical and pseudo-cylindrical projections.
545546 if self .projection in _cylproj or self .projection in _pseudocyl :
546547 if x .ndim == 1 :
547- x = self .shiftdata (x )
548+ x = self .shiftdata (x , fix_wrap_around = plotfunc . __name__ not in [ "scatter" ] )
548549 elif x .ndim == 0 :
549550 if x > 180 :
550551 x = x - 360.
@@ -4723,7 +4724,7 @@ def _ax_plt_from_kw(self, kw):
47234724 _ax = plt .gca ()
47244725 return _ax , plt
47254726
4726- def shiftdata (self ,lonsin ,datain = None ,lon_0 = None ):
4727+ def shiftdata (self ,lonsin ,datain = None ,lon_0 = None , fix_wrap_around = True ):
47274728 """
47284729 Shift longitudes (and optionally data) so that they match map projection region.
47294730 Only valid for cylindrical/pseudo-cylindrical global projections and data
@@ -4746,6 +4747,13 @@ def shiftdata(self,lonsin,datain=None,lon_0=None):
47464747 datain original 1-d or 2-d data. Default None.
47474748 lon_0 center of map projection region. Defaut None,
47484749 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.
47494757 ============== ====================================================
47504758
47514759 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):
47844792
47854793 # if no shift necessary, itemindex will be
47864794 # empty, so don't do anything
4787- if itemindex :
4795+ if fix_wrap_around and itemindex :
47884796 # check to see if cyclic (wraparound) point included
47894797 # if so, remove it.
47904798 if np .abs (lonsin1 [0 ]- lonsin1 [- 1 ]) < 1.e-4 :
@@ -4811,13 +4819,7 @@ def shiftdata(self,lonsin,datain=None,lon_0=None):
48114819 datain_save [:,1 :] = datain
48124820 datain_save [:,0 ] = datain [:,- 1 ]
48134821 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+
48214823 # 1-d data.
48224824 elif lonsin .ndim == 1 :
48234825 nlons = len (lonsin )
@@ -4832,7 +4834,7 @@ def shiftdata(self,lonsin,datain=None,lon_0=None):
48324834 else :
48334835 itemindex = 0
48344836
4835- if itemindex :
4837+ if fix_wrap_around and itemindex :
48364838 # check to see if cyclic (wraparound) point included
48374839 # if so, remove it.
48384840 if np .abs (lonsin [0 ]- lonsin [- 1 ]) < 1.e-4 :
@@ -4856,12 +4858,14 @@ def shiftdata(self,lonsin,datain=None,lon_0=None):
48564858 datain_save [1 :] = datain
48574859 datain_save [0 ] = datain [- 1 ]
48584860 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+
48654869 if datain is not None :
48664870 return lonsin , datain
48674871 else :
0 commit comments