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 axis3d to include offset text in tight bounding box calculation#30760

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
FazeelUsmani wants to merge6 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromFazeelUsmani:fix-axis3d-offset-text-tightbbox
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
2 changes: 2 additions & 0 deletionslib/mpl_toolkits/mplot3d/axis3d.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -708,6 +708,8 @@ def get_tightbbox(self, renderer=None, *, for_layout_only=False):
bb_1, bb_2 = self._get_ticklabel_bboxes(ticks, renderer)
other = []

if self.offsetText.get_visible() and self.offsetText.get_text():
other.append(self.offsetText.get_window_extent(renderer))
if self.line.get_visible():
other.append(self.line.get_window_extent(renderer))
if (self.label.get_visible() and not for_layout_only and
Expand Down
47 changes: 47 additions & 0 deletionslib/mpl_toolkits/mplot3d/tests/test_axes3d.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2733,3 +2733,50 @@ def test_axes3d_set_aspect_deperecated_params():

with pytest.raises(ValueError, match="adjustable"):
ax.set_aspect('equal', adjustable='invalid_value')


def test_axis_get_tightbbox_includes_offset_text():
# Test that axis.get_tightbbox includes the offset_text
# Regression test for issue #30744
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# Create data with high precision values that trigger offset text
Z = np.array([[0.1, 0.100000001], [0.100000000001, 0.100000000]])
ny, nx = Z.shape
x = np.arange(nx)
y = np.arange(ny)
X, Y = np.meshgrid(x, y)

ax.plot_surface(X, Y, Z)

# Force a draw to ensure offset text is created and positioned
fig.canvas.draw()
renderer = fig.canvas.get_renderer()

# Get the z-axis (which should have the offset text)
zaxis = ax.zaxis

# Check that offset text is visible and has content
# The offset text may not be visible on all backends/configurations,
# so we only test the inclusion when it's actually present
if (zaxis.offsetText.get_visible() and
zaxis.offsetText.get_text()):
offset_bbox = zaxis.offsetText.get_window_extent(renderer)

# Get the tight bbox - this should include the offset text
bbox = zaxis.get_tightbbox(renderer)
assert bbox is not None
assert offset_bbox is not None

# The tight bbox should fully contain the offset text bbox
# Check that offset_bbox is within bbox bounds (with small tolerance for
# floating point errors)
assert bbox.x0 <= offset_bbox.x0 + 1e-6, \
f"bbox.x0 ({bbox.x0}) should be <= offset_bbox.x0 ({offset_bbox.x0})"
assert bbox.y0 <= offset_bbox.y0 + 1e-6, \
f"bbox.y0 ({bbox.y0}) should be <= offset_bbox.y0 ({offset_bbox.y0})"
assert bbox.x1 >= offset_bbox.x1 - 1e-6, \
f"bbox.x1 ({bbox.x1}) should be >= offset_bbox.x1 ({offset_bbox.x1})"
assert bbox.y1 >= offset_bbox.y1 - 1e-6, \
f"bbox.y1 ({bbox.y1}) should be >= offset_bbox.y1 ({offset_bbox.y1})"

[8]ページ先頭

©2009-2025 Movatter.jp