@@ -5108,7 +5108,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
5108
5108
def errorbar (self , x , y , yerr = None , xerr = None ,
5109
5109
fmt = '-' , ecolor = None , elinewidth = None , capsize = 3 ,
5110
5110
barsabove = False , lolims = False , uplims = False ,
5111
- xlolims = False , xuplims = False , ** kwargs ):
5111
+ xlolims = False , xuplims = False , errorevery = 1 , ** kwargs ):
5112
5112
"""
5113
5113
call signature::
5114
5114
@@ -5157,6 +5157,11 @@ def errorbar(self, x, y, yerr=None, xerr=None,
5157
5157
only upper/lower limits. In that case a caret symbol is
5158
5158
used to indicate this. lims-arguments may be of the same
5159
5159
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.
5160
5165
5161
5166
All other keyword arguments are passed on to the plot command for the
5162
5167
markers. For example, this code makes big red squares with
@@ -5191,6 +5196,9 @@ def errorbar(self, x, y, yerr=None, xerr=None,
5191
5196
5192
5197
"""
5193
5198
5199
+ if errorevery < 1 :
5200
+ raise ValueError ('errorevery has to be a strictly positive integer ' )
5201
+
5194
5202
self ._process_unit_info (xdata = x , ydata = y , kwargs = kwargs )
5195
5203
if not self ._hold : self .cla ()
5196
5204
holdstate = self ._hold
@@ -5247,6 +5255,8 @@ def errorbar(self, x, y, yerr=None, xerr=None,
5247
5255
if not iterable (xuplims ): xuplims = np .array ([xuplims ]* len (x ), bool )
5248
5256
else : xuplims = np .asarray (xuplims , bool )
5249
5257
5258
+ everymask = np .arange (len (x )) % errorevery == 0
5259
+
5250
5260
def xywhere (xs , ys , mask ):
5251
5261
"""
5252
5262
return xs[mask], ys[mask] where mask is True but xs and
@@ -5285,33 +5295,38 @@ def xywhere(xs, ys, mask):
5285
5295
right = [thisx + thiserr for (thisx , thiserr )
5286
5296
in cbook .safezip (x ,xerr )]
5287
5297
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 ) )
5289
5301
if capsize > 0 :
5290
5302
if xlolims .any ():
5291
5303
# can't use numpy logical indexing since left and
5292
5304
# y are lists
5293
- leftlo , ylo = xywhere (left , y , xlolims )
5305
+ leftlo , ylo = xywhere (left , y , xlolims & everymask )
5294
5306
5295
5307
caplines .extend (
5296
5308
self .plot (leftlo , ylo , ls = 'None' ,
5297
5309
marker = mlines .CARETLEFT , ** plot_kw ) )
5298
5310
xlolims = ~ xlolims
5299
- leftlo , ylo = xywhere (left , y , xlolims )
5311
+ leftlo , ylo = xywhere (left , y , xlolims & everymask )
5300
5312
caplines .extend ( self .plot (leftlo , ylo , 'k|' , ** plot_kw ) )
5301
5313
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 ) )
5303
5317
5304
5318
if xuplims .any ():
5305
5319
5306
- rightup , yup = xywhere (right , y , xuplims )
5320
+ rightup , yup = xywhere (right , y , xuplims & everymask )
5307
5321
caplines .extend (
5308
5322
self .plot (rightup , yup , ls = 'None' ,
5309
5323
marker = mlines .CARETRIGHT , ** plot_kw ) )
5310
5324
xuplims = ~ xuplims
5311
- rightup , yup = xywhere (right , y , xuplims )
5325
+ rightup , yup = xywhere (right , y , xuplims & everymask )
5312
5326
caplines .extend ( self .plot (rightup , yup , 'k|' , ** plot_kw ) )
5313
5327
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 ) )
5315
5330
5316
5331
if yerr is not None :
5317
5332
if (iterable (yerr ) and len (yerr )== 2 and
@@ -5328,31 +5343,35 @@ def xywhere(xs, ys, mask):
5328
5343
upper = [thisy + thiserr for (thisy , thiserr )
5329
5344
in cbook .safezip (y ,yerr )]
5330
5345
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 ) )
5332
5349
if capsize > 0 :
5333
5350
5334
5351
if lolims .any ():
5335
- xlo , lowerlo = xywhere (x , lower , lolims )
5352
+ xlo , lowerlo = xywhere (x , lower , lolims & everymask )
5336
5353
caplines .extend (
5337
5354
self .plot (xlo , lowerlo , ls = 'None' ,
5338
5355
marker = mlines .CARETDOWN , ** plot_kw ) )
5339
5356
lolims = ~ lolims
5340
- xlo , lowerlo = xywhere (x , lower , lolims )
5357
+ xlo , lowerlo = xywhere (x , lower , lolims & everymask )
5341
5358
caplines .extend ( self .plot (xlo , lowerlo , 'k_' , ** plot_kw ) )
5342
5359
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 ) )
5344
5362
5345
5363
if uplims .any ():
5346
- xup , upperup = xywhere (x , upper , uplims )
5364
+ xup , upperup = xywhere (x , upper , uplims & everymask )
5347
5365
5348
5366
caplines .extend (
5349
5367
self .plot (xup , upperup , ls = 'None' ,
5350
5368
marker = mlines .CARETUP , ** plot_kw ) )
5351
5369
uplims = ~ uplims
5352
- xup , upperup = xywhere (x , upper , uplims )
5370
+ xup , upperup = xywhere (x , upper , uplims & everymask )
5353
5371
caplines .extend ( self .plot (xup , upperup , 'k_' , ** plot_kw ) )
5354
5372
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 ) )
5356
5375
5357
5376
if not barsabove and fmt is not None :
5358
5377
l0 , = self .plot (x ,y ,fmt ,** kwargs )
0 commit comments