@@ -5108,7 +5108,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
51085108 def errorbar (self , x , y , yerr = None , xerr = None ,
51095109 fmt = '-' , ecolor = None , elinewidth = None , capsize = 3 ,
51105110 barsabove = False , lolims = False , uplims = False ,
5111- xlolims = False , xuplims = False , ** kwargs ):
5111+ xlolims = False , xuplims = False , errorevery = 1 , ** kwargs ):
51125112 """
51135113 call signature::
51145114
@@ -5157,6 +5157,11 @@ def errorbar(self, x, y, yerr=None, xerr=None,
51575157 only upper/lower limits. In that case a caret symbol is
51585158 used to indicate this. lims-arguments may be of the same
51595159 type as *xerr* and *yerr*.
5160+
5161+ *errorevery*: positive integer
5162+ subsamples the errorbars. Eg if everyerror=5, errorbars for every
5163+ 5-th datapoint will be plotted. The data plot itself still shows
5164+ all data points.
51605165
51615166 All other keyword arguments are passed on to the plot command for the
51625167 markers. For example, this code makes big red squares with
@@ -5191,6 +5196,9 @@ def errorbar(self, x, y, yerr=None, xerr=None,
51915196
51925197 """
51935198
5199+ if errorevery < 1 :
5200+ raise ValueError ('errorevery has to be a strictly positive integer ' )
5201+
51945202 self ._process_unit_info (xdata = x , ydata = y , kwargs = kwargs )
51955203 if not self ._hold : self .cla ()
51965204 holdstate = self ._hold
@@ -5247,6 +5255,8 @@ def errorbar(self, x, y, yerr=None, xerr=None,
52475255 if not iterable (xuplims ): xuplims = np .array ([xuplims ]* len (x ), bool )
52485256 else : xuplims = np .asarray (xuplims , bool )
52495257
5258+ everymask = np .arange (len (x )) % errorevery == 0
5259+
52505260 def xywhere (xs , ys , mask ):
52515261 """
52525262 return xs[mask], ys[mask] where mask is True but xs and
@@ -5285,33 +5295,38 @@ def xywhere(xs, ys, mask):
52855295 right = [thisx + thiserr for (thisx , thiserr )
52865296 in cbook .safezip (x ,xerr )]
52875297
5288- barcols .append ( self .hlines (y , left , right , ** lines_kw ) )
5298+ yo , _ = xywhere (y , right , everymask )
5299+ lo , ro = xywhere (left , right , everymask )
5300+ barcols .append ( self .hlines (yo , lo , ro , ** lines_kw ) )
52895301 if capsize > 0 :
52905302 if xlolims .any ():
52915303 # can't use numpy logical indexing since left and
52925304 # y are lists
5293- leftlo , ylo = xywhere (left , y , xlolims )
5305+ leftlo , ylo = xywhere (left , y , xlolims & everymask )
52945306
52955307 caplines .extend (
52965308 self .plot (leftlo , ylo , ls = 'None' ,
52975309 marker = mlines .CARETLEFT , ** plot_kw ) )
52985310 xlolims = ~ xlolims
5299- leftlo , ylo = xywhere (left , y , xlolims )
5311+ leftlo , ylo = xywhere (left , y , xlolims & everymask )
53005312 caplines .extend ( self .plot (leftlo , ylo , 'k|' , ** plot_kw ) )
53015313 else :
5302- caplines .extend ( self .plot (left , y , 'k|' , ** plot_kw ) )
5314+
5315+ leftlo , ylo = xywhere (left , y , everymask )
5316+ caplines .extend ( self .plot (leftlo , ylo , 'k|' , ** plot_kw ) )
53035317
53045318 if xuplims .any ():
53055319
5306- rightup , yup = xywhere (right , y , xuplims )
5320+ rightup , yup = xywhere (right , y , xuplims & everymask )
53075321 caplines .extend (
53085322 self .plot (rightup , yup , ls = 'None' ,
53095323 marker = mlines .CARETRIGHT , ** plot_kw ) )
53105324 xuplims = ~ xuplims
5311- rightup , yup = xywhere (right , y , xuplims )
5325+ rightup , yup = xywhere (right , y , xuplims & everymask )
53125326 caplines .extend ( self .plot (rightup , yup , 'k|' , ** plot_kw ) )
53135327 else :
5314- caplines .extend ( self .plot (right , y , 'k|' , ** plot_kw ) )
5328+ rightup , yup = xywhere (right , y , everymask )
5329+ caplines .extend ( self .plot (rightup , yup , 'k|' , ** plot_kw ) )
53155330
53165331 if yerr is not None :
53175332 if (iterable (yerr ) and len (yerr )== 2 and
@@ -5328,31 +5343,35 @@ def xywhere(xs, ys, mask):
53285343 upper = [thisy + thiserr for (thisy , thiserr )
53295344 in cbook .safezip (y ,yerr )]
53305345
5331- barcols .append ( self .vlines (x , lower , upper , ** lines_kw ) )
5346+ xo , _ = xywhere (x , lower , everymask )
5347+ lo , uo = xywhere (lower , upper , everymask )
5348+ barcols .append ( self .vlines (xo , lo , uo , ** lines_kw ) )
53325349 if capsize > 0 :
53335350
53345351 if lolims .any ():
5335- xlo , lowerlo = xywhere (x , lower , lolims )
5352+ xlo , lowerlo = xywhere (x , lower , lolims & everymask )
53365353 caplines .extend (
53375354 self .plot (xlo , lowerlo , ls = 'None' ,
53385355 marker = mlines .CARETDOWN , ** plot_kw ) )
53395356 lolims = ~ lolims
5340- xlo , lowerlo = xywhere (x , lower , lolims )
5357+ xlo , lowerlo = xywhere (x , lower , lolims & everymask )
53415358 caplines .extend ( self .plot (xlo , lowerlo , 'k_' , ** plot_kw ) )
53425359 else :
5343- caplines .extend ( self .plot (x , lower , 'k_' , ** plot_kw ) )
5360+ xlo , lowerlo = xywhere (x , lower , everymask )
5361+ caplines .extend ( self .plot (xlo , lowerlo , 'k_' , ** plot_kw ) )
53445362
53455363 if uplims .any ():
5346- xup , upperup = xywhere (x , upper , uplims )
5364+ xup , upperup = xywhere (x , upper , uplims & everymask )
53475365
53485366 caplines .extend (
53495367 self .plot (xup , upperup , ls = 'None' ,
53505368 marker = mlines .CARETUP , ** plot_kw ) )
53515369 uplims = ~ uplims
5352- xup , upperup = xywhere (x , upper , uplims )
5370+ xup , upperup = xywhere (x , upper , uplims & everymask )
53535371 caplines .extend ( self .plot (xup , upperup , 'k_' , ** plot_kw ) )
53545372 else :
5355- caplines .extend ( self .plot (x , upper , 'k_' , ** plot_kw ) )
5373+ xup , upperup = xywhere (x , upper , everymask )
5374+ caplines .extend ( self .plot (xup , upperup , 'k_' , ** plot_kw ) )
53565375
53575376 if not barsabove and fmt is not None :
53585377 l0 , = self .plot (x ,y ,fmt ,** kwargs )
0 commit comments