Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7f412e8

Browse filesBrowse files
committed
Modfied for PEP8 compatibility
1 parent cd778db commit 7f412e8
Copy full SHA for 7f412e8

File tree

Expand file treeCollapse file tree

1 file changed

+20
-15
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+20
-15
lines changed

‎examples/statistics/errorbars_and_boxes.py

Copy file name to clipboardExpand all lines: examples/statistics/errorbars_and_boxes.py
+20-15Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,51 @@
1+
'''
2+
Example to create boxes from error using PatchCollection
3+
'''
4+
15
import numpy as np
26
import matplotlib.pyplot as plt
37
from matplotlib.collections import PatchCollection
48
from matplotlib.patches import Rectangle
59

610
# Number of data points
7-
n=5
11+
n = 5
812

913
# Dummy data
10-
x=np.arange(0,n,1)
11-
y=np.random.rand(n)*5.
14+
x = np.arange(0, n, 1)
15+
y = np.random.rand(n)*5.
1216

1317
# Dummy errors (above and below)
14-
xerr=np.random.rand(2,n)
15-
yerr=np.random.rand(2,n)
16-
17-
print xerr[:,0]
18+
xerr = np.random.rand(2, n)
19+
yerr = np.random.rand(2, n)
1820

1921
# Create figure and axes
20-
fig,ax = plt.subplots(1)
22+
fig, ax = plt.subplots(1)
2123

2224
# Plot data points
23-
ax.errorbar(x,y,xerr=xerr,yerr=yerr,fmt='None',ecolor='k')
25+
ax.errorbar(x, y, xerr=xerr, yerr=yerr, fmt='None', ecolor='k')
26+
2427

25-
# Function to plot error boxes
26-
def makeErrorBoxes(xdata,ydata,xerror,yerror,fc='r',ec='None',alpha=0.5):
28+
def makeErrorBoxes(xdata, ydata, xerror, yerror, fc='r', ec='None', alpha=0.5):
29+
'''
30+
Function to create error boxes
31+
'''
2732

2833
# Create list for all the error patches
2934
errorboxes = []
3035

3136
# Loop over data points; create box from errors at each point
32-
for xc,yc,xe,ye in zip(xdata,ydata,xerror.T,yerror.T):
33-
rect = Rectangle((xc-xe[0],yc-ye[0]),xe.sum(),ye.sum())
37+
for xc, yc, xe, ye in zip(xdata, ydata, xerror.T, yerror.T):
38+
rect = Rectangle((xc-xe[0], yc-ye[0]), xe.sum(), ye.sum())
3439
errorboxes.append(rect)
3540

3641
# Create patch collection with specified colour/alpha
37-
pc = PatchCollection(errorboxes,facecolor=fc,alpha=alpha,edgecolor=ec)
42+
pc = PatchCollection(errorboxes, facecolor=fc, alpha=alpha, edgecolor=ec)
3843

3944
# Add collection to axes
4045
ax.add_collection(pc)
4146

4247
# Call function to create error boxes
43-
makeErrorBoxes(x,y,xerr,yerr)
48+
makeErrorBoxes(x, y, xerr, yerr)
4449

4550
# Add some space around the data points on the axes
4651
ax.margins(0.1)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.