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

FIX: the new _AxesStack with np.array as input#9029

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

Closed
tacaswell wants to merge2 commits intomatplotlib:masterfromtacaswell:fix_axesstack
Closed
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
37 changes: 36 additions & 1 deletionlib/matplotlib/figure.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -163,6 +163,38 @@ class _AxesStack(object):
"""Lightweight stack that tracks Axes in a Figure.
"""

@staticmethod
def __key_compare(k1, k2):
k1_args, k1_kwargs = k1
k2_args, k2_kwargs = k2

def np_safe_eq(left, right):
out = (left == right)
try:
out = bool(out)
except ValueError:
out = out.all()
try:
out &= len(left) == len(right)
except TypeError:
out = False
return out

for a, b in zip(k1_args, k2_args):
test = np_safe_eq(a, b)
if not test:
return False
if set(k1_kwargs) != set(k2_kwargs):
return False

for k in k1_kwargs:
a = k1_kwargs[k]
b = k2_kwargs[k]
test = np_safe_eq(a, b)
if not test:
return False
return True

def __init__(self):
# We maintain a list of (creation_index, key, axes) tuples.
# We do not use an OrderedDict because 1. the keys may not be hashable
Expand All@@ -179,7 +211,10 @@ def as_list(self):
def get(self, key):
"""Find the axes corresponding to a key; defaults to `None`.
"""
return next((ax for _, k, ax in self._items if k == key), None)
return next((ax
for _, k, ax in self._items
if self.__key_compare(k, key)),
None)

def current_key_axes(self):
"""Return the topmost `(key, axes)` pair, or `(None, None)` if empty.
Expand Down
8 changes: 8 additions & 0 deletionslib/matplotlib/tests/test_figure.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -319,3 +319,11 @@ def test_subplots_shareax_loglabels():

for ax in ax_arr[:, 0]:
assert 0 < len(ax.yaxis.get_ticklabels(which='both'))


def test_axes_add_np_behavior():
ax1 = plt.axes(np.array([.1, .1, .8, .8]))
ax2 = plt.axes(np.array([.1, .1, .8, .8]))
# in the future this test will need to be changed to not assert
# that the axes are equal, but still check that this does not blowup.
assert ax1 is ax2

[8]ページ先頭

©2009-2025 Movatter.jp