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

Skip to content

inconsistent behaviour of the errorevery option in pyplot.errorbar() to the markevery keyword #4438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
monodera opened this issue May 17, 2015 · 2 comments
Labels
API: consistency Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Documentation
Milestone

Comments

@monodera
Copy link

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.

@tacaswell tacaswell added this to the next point release milestone May 17, 2015
@tacaswell tacaswell added API: consistency Documentation Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues and removed Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues labels May 17, 2015
@tacaswell
Copy link
Member

fair point.

All of the input options to markevery are a relatively new feature. I am glad you are finding it useful enough to wish it were else where!

@tacaswell tacaswell modified the milestones: next point release, proposed next point release Jul 11, 2015
@petehuang
Copy link
Contributor

Reconfirming in 1.5.3 with Python 2.7.12

@tacaswell tacaswell modified the milestones: 2.2 (next next feature release), 2.1 (next point release) Jan 10, 2017
@QuLogic QuLogic modified the milestones: needs sorting, v3.4.0 Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: consistency Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Documentation
Projects
None yet
Development

No branches or pull requests

4 participants