-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
inconsistent behaviour of the errorevery option in pyplot.errorbar() to the markevery keyword #4438
Description
When I set markevery and errorevery keywords together in pyplot.errorbar(), it works only in the case for an integer parameter. However, though the markevery keyword in pyplot.plot() allows more options as an input ([None | int | length-2 tuple of int | slice | list/array of int | float | length-2 tuple of float]), errorbar() cannot handle such options. It would be nice if errorevery can accept the same kind of inputs as markevery.
Here is a piece of code which demonstrates the issue.
import numpy as np
import matplotlib.pyplot as plt
# make data arrays
ndata = 10
x = np.linspace(0, 1, ndata)
y = np.linspace(0, 1, ndata)
yerror = np.ones(x.size)*0.1
# plot
fig = plt.figure(figsize=(12,12))
ax1 = fig.add_subplot(221)
ax1.errorbar(x, y, yerr=yerror, fmt='o')
ax1.set_title("plot all points")
ax1.set_xlim(-0.1, 1.1)
ax1.set_ylim(-0.1, 1.1)
index_plot = [1, 2, 8, 9]
ax2 = fig.add_subplot(222)
ax2.errorbar(x, y, yerr=yerror, fmt='o', markevery=index_plot)
ax2.set_title("set markevery with an array of index")
ax2.set_xlim(-0.1, 1.1)
ax2.set_ylim(-0.1, 1.1)
ax3 = fig.add_subplot(223)
ax3.errorbar(x, y, yerr=yerror, fmt='o', markevery=2, errorevery=2)
ax3.set_title("set markevery and errorevery with an integer")
ax3.set_xlim(-0.1, 1.1)
ax3.set_ylim(-0.1, 1.1)
# the following does not work
ax4 = fig.add_subplot(224)
ax4.errorbar(x, y, yerr=yerror, fmt='o', markevery=index_plot, errorevery=index_plot)
ax4.set_title("set markevery and errorevery together with an array")
ax4.set_xlim(-0.1, 1.1)
ax4.set_ylim(-0.1, 1.1)I got the following error message.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-43-81e2a2ded427> in <module>()
21
22 ax4 = fig.add_subplot(224)
---> 23 ax4.errorbar(x, y, yerr=yerror, fmt='o', markevery=index_plot, errorevery=index_plot)
24 ax4.set_title("set markevery and errorevery together with an array")
25 ax4.set_xlim(-0.1, 1.1)
/usr/local/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in errorbar(self, x, y, yerr, xerr, fmt, ecolor, elinewidth, capsize, barsabove, lolims, uplims, xlolims, xuplims, errorevery, capthick, **kwargs)
2713 xuplims = np.asarray(xuplims, bool)
2714
-> 2715 everymask = np.arange(len(x)) % errorevery == 0
2716
2717 def xywhere(xs, ys, mask):
ValueError: operands could not be broadcast together with shapes (10,) (4,) As a kind of bi-product, I found that a bool array with a length of N is also accepted as a valid input for markevery, but it's not documented in the manual (http://matplotlib.org/api/lines_api.html#matplotlib.lines.Line2D.set_markevery). For example, I can use index_plot=[True, False, False, True, True, True, True, True, False, False] in the example above.
I'm using matplotlib 1.4.3 with Python 2.7.9.