Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Added a new example to create error boxes using a PatchCollection #6596
Conversation
mdboom
added the
needs_review
label
Jun 16, 2016
|
Thanks for doing this! Can you run this through a pep8 linter? closes #6593 |
tacaswell
added this to the
2.1 (next point release)
milestone
Jun 16, 2016
|
No problem, I think that should be ok now? |
WeatherGod
and 1 other
commented on an outdated diff
Jun 16, 2016
| + | ||
| +# Dummy errors (above and below) | ||
| +xerr = np.random.rand(2, n) | ||
| +yerr = np.random.rand(2, n) | ||
| + | ||
| +# Create figure and axes | ||
| +fig, ax = plt.subplots(1) | ||
| + | ||
| +# Plot data points | ||
| +ax.errorbar(x, y, xerr=xerr, yerr=yerr, fmt='None', ecolor='k') | ||
| + | ||
| + | ||
| +def makeErrorBoxes(xdata, ydata, xerror, yerror, fc='r', ec='None', alpha=0.5): | ||
| + ''' | ||
| + Function to create error boxes | ||
| + ''' |
WeatherGod
Member
|
WeatherGod
and 1 other
commented on an outdated diff
Jun 16, 2016
| + # Loop over data points; create box from errors at each point | ||
| + for xc, yc, xe, ye in zip(xdata, ydata, xerror.T, yerror.T): | ||
| + rect = Rectangle((xc-xe[0], yc-ye[0]), xe.sum(), ye.sum()) | ||
| + errorboxes.append(rect) | ||
| + | ||
| + # Create patch collection with specified colour/alpha | ||
| + pc = PatchCollection(errorboxes, facecolor=fc, alpha=alpha, edgecolor=ec) | ||
| + | ||
| + # Add collection to axes | ||
| + ax.add_collection(pc) | ||
| + | ||
| +# Call function to create error boxes | ||
| +makeErrorBoxes(x, y, xerr, yerr) | ||
| + | ||
| +# Add some space around the data points on the axes | ||
| +ax.margins(0.1) |
|
|
WeatherGod
and 3 others
commented on an outdated diff
Jun 16, 2016
| + # Create list for all the error patches | ||
| + errorboxes = [] | ||
| + | ||
| + # Loop over data points; create box from errors at each point | ||
| + for xc, yc, xe, ye in zip(xdata, ydata, xerror.T, yerror.T): | ||
| + rect = Rectangle((xc-xe[0], yc-ye[0]), xe.sum(), ye.sum()) | ||
| + errorboxes.append(rect) | ||
| + | ||
| + # Create patch collection with specified colour/alpha | ||
| + pc = PatchCollection(errorboxes, facecolor=fc, alpha=alpha, edgecolor=ec) | ||
| + | ||
| + # Add collection to axes | ||
| + ax.add_collection(pc) | ||
| + | ||
| +# Call function to create error boxes | ||
| +makeErrorBoxes(x, y, xerr, yerr) |
WeatherGod
Member
|
|
Some suggestions (partially rendundant with other comments):
|
WeatherGod
merged commit 25ce666
into matplotlib:master
Jun 18, 2016
mdboom
removed the
needs_review
label
Jun 18, 2016
|
does this get backported anywhere? |
|
I think it should go into 2.x too |
WeatherGod
added a commit
that referenced
this pull request
Jul 14, 2016
|
|
WeatherGod |
9ea7315
|
|
backported to v2.x via 9ea7315 |
tmdavison commentedJun 16, 2016
Adding a new example I first created here: http://stackoverflow.com/a/37856171/588071