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

AddU,V andC setter toQuiver#26410

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

Open
ericpre wants to merge7 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromericpre:quiver_setters
Open
Show file tree
Hide file tree
Changes from1 commit
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
PrevPrevious commit
NextNext commit
Addset_offsets toquiver and make the attribute (N andXY) p…
…roperties to avoid inconsistent state of `quiver`
  • Loading branch information
@ericpre
ericpre committedMar 23, 2024
commit10adf0b6b906f6989fc93a77951679bfb63bde33
26 changes: 23 additions & 3 deletionslib/matplotlib/quiver.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -447,7 +447,7 @@ class Quiver(mcollections.PolyCollection):
The API methods are set_UVC(), set_U(), set_V() and set_C(), which
can be used to change the size, orientation, and color of the
arrows; their locations are fixed when the class is
instantiated. Possiblythis method will be useful
instantiated. Possiblythese methods will be useful
in animations.

Much of the work in this class is done in the draw()
Expand DownExpand Up@@ -475,8 +475,6 @@ def __init__(self, ax, *args,
X, Y, U, V, C = _parse_args(*args, caller_name='quiver')
self.X = X
self.Y = Y
self.XY = np.column_stack((X, Y))
self.N = len(X)
self.scale = scale
self.headwidth = headwidth
self.headlength = float(headlength)
Expand DownExpand Up@@ -523,6 +521,14 @@ def _init(self):

self._dpi_at_last_init = self.axes.figure.dpi

@property
def N(self):
return len(self.X)

@property
def XY(self):
return np.column_stack((self.X, self.Y))
Copy link
Member

Choose a reason for hiding this comment

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

It makes sense that these should not be ordinary public attributes because they should not be set directly by the user. However I wonder if it would be better to make them private attributes and (if we think it's needed) implementget_N andget_XY for consistency with other parts of the library. Also do we need to go through the deprecation pathway to prevent setting of these?


def get_datalim(self, transData):
trans = self.get_transform()
offset_trf = self.get_offset_transform()
Expand DownExpand Up@@ -588,6 +594,7 @@ def set_UVC(self, U, V, C=None):
The size must the same as the existing U, V or be one.
C : array-like or None, optional
The arrow colors. The default is None.
The size must the same as the existing U, V or be one.
"""
if U is None:
U = self.U
Expand DownExpand Up@@ -619,6 +626,19 @@ def set_UVC(self, U, V, C=None):
self.set_array(C)
self.stale = True

def set_offsets(self, xy):
Copy link
Member

Choose a reason for hiding this comment

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

change toset_XY to match input naming.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Good point. I addedset_offsets to be consistent with other collections. An alternative would be to renameXY tooffsets everywhere? Maybe for another PR! 😅

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I have keep bothset_XY andset_offsets, withset_XY being an alias ofset_offsets and documented as such.

I still think that it would be simple to keep onlyset_offsets because of its consistency with others collections but also because it is possible to useset_X andset_Y which match the constructor (set_XY doesn't match anything really).

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I removedset_XY/get_XY to keep the API simple for the following reason:

  • it doesn't match the constructor arguments
  • theX,Y setter/getter are matching the constructor arguments
  • it is an alias to setter/getter of the base class (Collection).

"""
Set the offsets for the arrows. This saves the offsets passed
in and masks them as appropriate for the existing X/Y data.

Parameters
----------
xy : sequence of pairs of floats
"""
self.X, self.Y = xy[:, 0], xy[:, 1]
super().set_offsets(xy)
self.stale = True

def _dots_per_unit(self, units):
"""Return a scale factor for converting from units to pixels."""
bb = self.axes.bbox
Expand Down
7 changes: 5 additions & 2 deletionslib/matplotlib/quiver.pyi
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,11 +54,9 @@ class QuiverKey(martist.Artist):
class Quiver(mcollections.PolyCollection):
X: ArrayLike
Y: ArrayLike
XY: ArrayLike
U: ArrayLike
V: ArrayLike
Umask: ArrayLike
N: int
scale: float | None
headwidth: float
headlength: float
Expand DownExpand Up@@ -121,13 +119,18 @@ class Quiver(mcollections.PolyCollection):
pivot: Literal["tail", "mid", "middle", "tip"] = ...,
**kwargs
) -> None: ...
@property
def N(self) -> int: ...
@property
def XY(self) -> ArrayLike: ...
def get_datalim(self, transData: Transform) -> Bbox: ...
def set_U(self, U: ArrayLike) -> None: ...
def set_V(self, V: ArrayLike) -> None: ...
def set_C(self, C: ArrayLike) -> None: ...
def set_UVC(
self, U: ArrayLike | None, V: ArrayLike | None, C: ArrayLike | None = ...
) -> None: ...
def set_offsets(self, xy: ArrayLike) -> None: ...

class Barbs(mcollections.PolyCollection):
sizes: dict[str, float]
Expand Down
3 changes: 3 additions & 0 deletionslib/matplotlib/tests/test_collections.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -376,6 +376,9 @@ def test_quiver_offsets():
qc.set_offsets(new_offsets)

np.testing.assert_allclose(qc.get_offsets(), new_offsets)
np.testing.assert_allclose(qc.X, new_offsets[::, 0])
np.testing.assert_allclose(qc.Y, new_offsets[::, 1])
np.testing.assert_allclose(qc.XY, new_offsets)


def test_quiver_UVC():
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp