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 Update Axes limits from Axes.add_collection(... autolim=True)#30327

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:fix-autolim
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
6 changes: 5 additions & 1 deletionlib/matplotlib/axes/_base.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2361,7 +2361,11 @@ def add_collection(self, collection, autolim=True):
# the call so that self.dataLim will update its own minpos.
# This ensures that log scales see the correct minimum.
points = np.concatenate([points, [datalim.minpos]])
self.update_datalim(points)
# only update the dataLim for x/y if the collection uses transData
# in this direction.
updatex, updatey = (collection.get_transform()
.contains_branch_seperately(self.transData))
self.update_datalim(points, updatex=updatex, updatey=updatey)

self.stale = True
return collection
Expand Down
22 changes: 14 additions & 8 deletionslib/matplotlib/tests/test_collections.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -899,17 +899,23 @@ def test_collection_set_array():


def test_blended_collection_autolim():
a = [1, 2, 4]
height = .2
f, ax = plt.subplots()

xy_pairs = np.column_stack([np.repeat(a, 2), np.tile([0, height], len(a))])
line_segs = xy_pairs.reshape([len(a), 2, 2])
# sample data to give initial data limits
ax.plot([2, 3, 4], [0.4, 0.6, 0.5])
np.testing.assert_allclose((ax.dataLim.xmin, ax.dataLim.xmax), (2, 4))
data_ymin, data_ymax = ax.dataLim.ymin, ax.dataLim.ymax

f, ax = plt.subplots()
# LineCollection with vertical lines spanning the Axes vertical, using transAxes
x = [1, 2, 3, 4, 5]
vertical_lines = [np.array([[xi, 0], [xi, 1]]) for xi in x]
trans = mtransforms.blended_transform_factory(ax.transData, ax.transAxes)
ax.add_collection(LineCollection(line_segs, transform=trans))
ax.autoscale_view(scalex=True, scaley=False)
np.testing.assert_allclose(ax.get_xlim(), [1., 4.])
ax.add_collection(LineCollection(vertical_lines, transform=trans))

# check that the x data limits are updated to include the LineCollection
np.testing.assert_allclose((ax.dataLim.xmin, ax.dataLim.xmax), (1, 5))
# check that the y data limits are not updated (because they are not transData)
np.testing.assert_allclose((ax.dataLim.ymin, ax.dataLim.ymax), (0.4, 0.6))
Comment on lines +904 to +918
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Note 1: Before, the test did only check that the x data limits were expanded. It did not investigate the y data limits. Now it also ensures, that y data limits are not changed.

Note 2: I've switched from testing view limits to testing data limits, because that's the relevant quantity autolim influences. We save theautoscale_view() by not looking at the view limits.



def test_singleton_autolim():
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp