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

MNT: Improve Grouper#30754

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
timhoffm wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromtimhoffm:mnt-grouper
Open
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
10 changes: 6 additions & 4 deletionslib/matplotlib/axes/_base.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4756,13 +4756,15 @@ def twiny(self, axes_class=None, **kwargs):
ax2.yaxis.units = self.yaxis.units
return ax2

def get_shared_x_axes(self):
@classmethod
def get_shared_x_axes(cls):
"""Return an immutable view on the shared x-axes Grouper."""
return cbook.GrouperView(self._shared_axes["x"])
return cbook.GrouperView(cls._shared_axes["x"])

def get_shared_y_axes(self):
@classmethod
def get_shared_y_axes(cls):
"""Return an immutable view on the shared y-axes Grouper."""
return cbook.GrouperView(self._shared_axes["y"])
return cbook.GrouperView(cls._shared_axes["y"])

def label_outer(self, remove_inner_ticks=False):
"""
Expand Down
6 changes: 4 additions & 2 deletionslib/matplotlib/axes/_base.pyi
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -388,8 +388,10 @@ class _AxesBase(martist.Artist):
) -> Bbox | None: ...
def twinx(self, axes_class: Axes | None = ..., **kwargs) -> Axes: ...
def twiny(self, axes_class: Axes | None = ..., **kwargs) -> Axes: ...
def get_shared_x_axes(self) -> cbook.GrouperView: ...
def get_shared_y_axes(self) -> cbook.GrouperView: ...
@classmethod
def get_shared_x_axes(cls) -> cbook.GrouperView: ...
@classmethod
def get_shared_y_axes(cls) -> cbook.GrouperView: ...
def label_outer(self, remove_inner_ticks: bool = ...) -> None: ...

# The methods underneath this line are added via the `_axis_method_wrapper` class
Expand Down
2 changes: 1 addition & 1 deletionlib/matplotlib/axis.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -703,7 +703,7 @@ def isDefault_minfmt(self, value):
self.minor._formatter_is_default = value

def _get_shared_axes(self):
"""ReturnGrouper of shared Axes for current axis."""
"""Returna list of shared Axes for current axis."""
return self.axes._shared_axes[
self._get_axis_name()].get_siblings(self.axes)

Expand Down
21 changes: 15 additions & 6 deletionslib/matplotlib/cbook.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
"""
A collection of utility functions and classes. Originally, many
(but not all) were from the Python Cookbook -- hence the name cbook.
Expand DownExpand Up@@ -886,10 +886,17 @@
for group in unique_groups.values():
yield sorted(group, key=self._ordering.__getitem__)

def get_siblings(self, a):
"""Return all of the items joined with *a*, including itself."""
def get_siblings(self, a, *, include_self=True):
"""
Return all the items joined with *a*.

*a* is included in the list if *include_self* is True.
"""
siblings = self._mapping.get(a, [a])
return sorted(siblings, key=self._ordering.get)
result = sorted(siblings, key=self._ordering.get)
if not include_self:
result.remove(a)
return result


class GrouperView:
Expand All@@ -905,11 +912,13 @@
"""
return self._grouper.joined(a, b)

def get_siblings(self, a):
def get_siblings(self, a, *, include_self=True):
"""
Return all of the items joined with *a*, including itself.
Return all the items joined with *a*.

*a* is included in the list if *include_self* is True.
"""
return self._grouper.get_siblings(a)
return self._grouper.get_siblings(a, include_self=include_self)


def simple_linear_interpolation(a, steps):
Expand Down
4 changes: 2 additions & 2 deletionslib/matplotlib/cbook.pyi
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -107,14 +107,14 @@ class Grouper(Generic[_T]):
def joined(self, a: _T, b: _T) -> bool: ...
def remove(self, a: _T) -> None: ...
def __iter__(self) -> Iterator[list[_T]]: ...
def get_siblings(self, a: _T) -> list[_T]: ...
def get_siblings(self, a: _T, *, include_self: bool = True) -> list[_T]: ...

class GrouperView(Generic[_T]):
def __init__(self, grouper: Grouper[_T]) -> None: ...
def __contains__(self, item: _T) -> bool: ...
def __iter__(self) -> Iterator[list[_T]]: ...
def joined(self, a: _T, b: _T) -> bool: ...
def get_siblings(self, a: _T) -> list[_T]: ...
def get_siblings(self, a: _T, *, include_self: bool = True) -> list[_T]: ...

def simple_linear_interpolation(a: ArrayLike, steps: int) -> np.ndarray: ...
def delete_masked_points(*args): ...
Expand Down
2 changes: 1 addition & 1 deletionlib/matplotlib/figure.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
"""
`matplotlib.figure` implements the following classes:

Expand DownExpand Up@@ -947,7 +947,7 @@

for name in ax._axis_names: # Break link between any shared Axes
grouper = ax._shared_axes[name]
siblings =[other for other ingrouper.get_siblings(ax) if other is not ax]
siblings = grouper.get_siblings(ax, include_self=False)
if not siblings: # Axes was not shared along this axis; we're done.
continue
grouper.remove(ax)
Expand Down
1 change: 1 addition & 0 deletionslib/matplotlib/tests/test_cbook.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -622,6 +622,7 @@ class Dummy:
g.join(*objs)
assert set(list(g)[0]) == set(objs)
assert set(g.get_siblings(a)) == set(objs)
assert a not in g.get_siblings(a, include_self=False)

for other in objs[1:]:
assert g.joined(a, other)
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp