Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b674fc1

Browse files
committed
added example to show errorbar subsampling and extended the doc as well as the validity check for errorevery keyword of errorbar.
1 parent b1889d2 commit b674fc1

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2012-02-29 errorevery keyword added to errorbar to enable errorbar
2+
subsampling. fixes issue #600.
3+
14
2011-12-29 ps and pdf markers are now stroked only if the line width
25
is nonzero for consistency with agg, fixes issue #621. - JKS
36

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'''
2+
Demo for the errorevery keyword to show data full accuracy data plots with
3+
few errorbars.
4+
'''
5+
6+
import numpy as np
7+
import matplotlib.pyplot as plt
8+
9+
# example data
10+
x = np.arange(0.1, 4, 0.1)
11+
y = np.exp(-x)
12+
13+
# example variable error bar values
14+
yerr = 0.1 + 0.1*np.sqrt(x)
15+
16+
17+
# Now switch to a more OO interface to exercise more features.
18+
fig, axs = plt.subplots(nrows=1, ncols=2, sharex=True)
19+
ax = axs[0]
20+
ax.errorbar(x, y, yerr=yerr)
21+
ax.set_title('all errorbars')
22+
23+
ax = axs[1]
24+
ax.errorbar(x, y, yerr=yerr, errorevery=5)
25+
ax.set_title('only every 5th errorbar')
26+
27+
28+
fig.suptitle('Errorbar subsampling for better visualibility')
29+
30+
plt.show()

lib/matplotlib/axes.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5159,7 +5159,8 @@ def errorbar(self, x, y, yerr=None, xerr=None,
51595159
51605160
*errorevery*: positive integer
51615161
subsamples the errorbars. Eg if everyerror=5, errorbars for every
5162-
5-th datapoint will be plotted.
5162+
5-th datapoint will be plotted. The data plot itself still shows
5163+
all data points.
51635164
51645165
All other keyword arguments are passed on to the plot command for the
51655166
markers. For example, this code makes big red squares with
@@ -5194,6 +5195,9 @@ def errorbar(self, x, y, yerr=None, xerr=None,
51945195
51955196
"""
51965197

5198+
if errorevery < 1:
5199+
raise ValueError('errorevery has to be a strictly positive integer ')
5200+
51975201
self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
51985202
if not self._hold: self.cla()
51995203
holdstate = self._hold

0 commit comments

Comments
 (0)