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

Appearance settings

Commit 4d9d142

Browse filesBrowse files
authored
Merge pull request #12693 from timhoffm/workaround-text3d-breaks-tightlayout
Workaround Text3D breaking tight_layout()
2 parents 9332a06 + 1a5a2cb commit 4d9d142
Copy full SHA for 4d9d142

File tree

Expand file treeCollapse file tree

2 files changed

+19
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-1
lines changed

‎lib/mpl_toolkits/mplot3d/art3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/art3d.py
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ def draw(self, renderer):
113113
mtext.Text.draw(self, renderer)
114114
self.stale = False
115115

116+
def get_tightbbox(self, renderer):
117+
# Overwriting the 2d Text behavior which is not valid for 3d.
118+
# For now, just return None to exclude from layout calculation.
119+
return None
120+
116121

117122
def text_2d_to_3d(obj, z=0, zdir='z'):
118123
"""Convert a Text to a Text3D object."""

‎lib/mpl_toolkits/tests/test_mplot3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/tests/test_mplot3d.py
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from mpl_toolkits.mplot3d import Axes3D, axes3d, proj3d, art3d
44
from matplotlib import cm
5-
from matplotlib.testing.decorators import image_comparison
5+
from matplotlib.testing.decorators import image_comparison, check_figures_equal
66
from matplotlib.collections import LineCollection
77
from matplotlib.patches import Circle
88
import matplotlib.pyplot as plt
@@ -163,6 +163,19 @@ def f(t):
163163
ax.set_zlim3d(-1, 1)
164164

165165

166+
@check_figures_equal(extensions=['png'])
167+
def test_tight_layout_text(fig_test, fig_ref):
168+
# text is currently ignored in tight layout. So the order of text() and
169+
# tight_layout() calls should not influence the result.
170+
ax1 = fig_test.gca(projection='3d')
171+
ax1.text(.5, .5, .5, s='some string')
172+
fig_test.tight_layout()
173+
174+
ax2 = fig_ref.gca(projection='3d')
175+
fig_ref.tight_layout()
176+
ax2.text(.5, .5, .5, s='some string')
177+
178+
166179
@image_comparison(baseline_images=['scatter3d'], remove_text=True)
167180
def test_scatter3d():
168181
fig = plt.figure()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.