Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Improve barbs() error message#7407

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
NelleV merged 2 commits intomatplotlib:v2.xfromdopplershift:barbs-error
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletionslib/matplotlib/quiver.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -392,6 +392,12 @@ def _parse_args(*args):
return X, Y, U, V, C


def _check_consistent_shapes(*arrays):
all_shapes = set(a.shape for a in arrays)
if len(all_shapes) != 1:
raise ValueError('The shapes of the passed in arrays do not match.')
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

Choose a reason for hiding this comment

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

I think that line is too long (pep8 is complaining somewhere).

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Nope, even worse--it was the docstring typo I fixed. I rewrapped and pushed.



class Quiver(mcollections.PolyCollection):
"""
Specialized PolyCollection for arrows.
Expand DownExpand Up@@ -1124,9 +1130,11 @@ def set_UVC(self, U, V, C=None):
x, y, u, v, c = delete_masked_points(self.x.ravel(),
self.y.ravel(),
self.u, self.v, c)
_check_consistent_shapes(x, y, u, v, c)
else:
x, y, u, v = delete_masked_points(self.x.ravel(), self.y.ravel(),
self.u, self.v)
_check_consistent_shapes(x, y, u, v)

magnitude = np.hypot(u, v)
flags, barbs, halves, empty = self._find_tails(magnitude,
Expand All@@ -1151,16 +1159,17 @@ def set_UVC(self, U, V, C=None):

def set_offsets(self, xy):
"""
Set the offsets for the barb polygons. This saves theoffets passed in
and actually sets version masked as appropriate for the existing U/V
data. *offsets* should be a sequence.
Set the offsets for the barb polygons. This saves theoffsets passed
inand actually sets version masked as appropriate for the existing
U/Vdata. *offsets* should be a sequence.

ACCEPTS: sequence of pairs of floats
"""
self.x = xy[:, 0]
self.y = xy[:, 1]
x, y, u, v = delete_masked_points(self.x.ravel(), self.y.ravel(),
self.u, self.v)
_check_consistent_shapes(x, y, u, v)
xy = np.hstack((x[:, np.newaxis], y[:, np.newaxis]))
mcollections.PolyCollection.set_offsets(self, xy)
self.stale = True
Expand Down
15 changes: 15 additions & 0 deletionslib/matplotlib/tests/test_quiver.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
from __future__ import print_function
import warnings
import numpy as np
from nose.tools import raises
import sys
from matplotlib import pyplot as plt
from matplotlib.testing.decorators import cleanup
Expand DownExpand Up@@ -133,6 +134,20 @@ def test_barbs():
cmap='viridis')


@cleanup
@raises(ValueError)
Copy link
Member

Choose a reason for hiding this comment

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

Just a thought: we could avoid falling back tonose with pytest like this:

@cleanupdeftest_bad_masked_sizes():'Test error handling when given differing sized masked arrays'x=np.arange(3)y=np.arange(3)u=np.ma.array(15.*np.ones((4,)))v=np.ma.array(15.*np.ones_like(u))u[1]=np.ma.maskedv[1]=np.ma.maskedfig,ax=plt.subplots()withpytest.raises(ValueError):ax.barbs(x,y,u,v)

NelleV reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

If we're allowed to explicitly use pytest now, I will absolutely do that. I just tried to be consistent with what's already around.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I'm not seeing anywhere that we're explicitly using pytest yet...I sense this shouldn't be the first. 😞

Copy link
Member

Choose a reason for hiding this comment

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

oh, I thought it was official!

Copy link
Member

Choose a reason for hiding this comment

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

I personally don't care… I much prefer nose's API than pytests, so I have a tendency to use naturally pytest. I'd be interested in knowing whether we should write everything pytest-like.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Ah...on master.

Copy link
Member

Choose a reason for hiding this comment

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

Oops. Sorry for the noise. I missed the destination for this.

def test_bad_masked_sizes():
'Test error handling when given differing sized masked arrays'
x = np.arange(3)
y = np.arange(3)
u = np.ma.array(15. * np.ones((4,)))
v = np.ma.array(15. * np.ones_like(u))
u[1] = np.ma.masked
v[1] = np.ma.masked
fig, ax = plt.subplots()
ax.barbs(x, y, u, v)


if __name__ == '__main__':
import nose
nose.runmodule()

[8]ページ先頭

©2009-2025 Movatter.jp