Skip to content
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

BUG : improved input clean up in Axes.{h|v}line #3014

Merged
merged 1 commit into from
Apr 28, 2014

Conversation

tacaswell
Copy link
Member

@efiring I suspect there is a better way to do this.

@tacaswell tacaswell added this to the v1.4.0 milestone Apr 27, 2014
if len(xmax) == 1:
xmax = np.resize(xmax, y.shape)
if y.ndim != 1:
raise ValueError("y must be scalar or 1D")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything in green above this point can be accomplished with

y = np.ravel(y)
xmin = np.ravel(xmin)
xmax = np.ravel(xmax)

or that could even be packed into a single line with map or a list comprehension. After doing this, there is no need to check the number of dimensions.
However, it looks like you are leaving out the critical resize operation. Everything needed could be done like this:

y = np.ravel(y)
xmin = np.resize(xmin, y.shape)
xmax = np.resize(xmax, y.shape)

Now, none of the checks in the blocks below are needed, either.
Note: unlike most plotting methods, this one does not support masked arrays; but it never did, so the simplification suggested here is not hurting anything.

 - passing in a (N, 1) shaped array as input causes the zipping to
   generate an extra dimension
 - closes matplotlib#2197
 - use ravel + reshape to do shape validation + getting rid of
   extra dimension
@tacaswell
Copy link
Member Author

@efiring Changed to use ravel

efiring added a commit that referenced this pull request Apr 28, 2014
BUG : improved input clean up in Axes.{h|v}line
@efiring efiring merged commit a6a09c1 into matplotlib:master Apr 28, 2014
@tacaswell tacaswell deleted the hline_vline_input_cleaning branch April 29, 2014 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pyplot.errorbar: problem with some shapes of the positional arguments
3 participants