8000 Workaround Text3D breaking tight_layout() by timhoffm · Pull Request #12693 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Workaround Text3D breaking tight_layout() #12693

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions lib/mpl_toolkits/mplot3d/art3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ def draw(self, renderer):
mtext.Text.draw(self, renderer)
self.stale = False

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


def text_2d_to_3d(obj, z=0, zdir='z'):
"""Convert a Text to a Text3D object."""
Expand Down
15 changes: 14 additions & 1 deletion lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from mpl_toolkits.mplot3d import Axes3D, axes3d, proj3d, art3d
from matplotlib import cm
from matplotlib.testing.decorators import image_comparison
from matplotlib.testing.decorators import image_comparison, check_figures_equal
from matplotlib.collections import LineCollection
from matplotlib.patches import Circle
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -163,6 +163,19 @@ def f(t):
ax.set_zlim3d(-1, 1)


@check_figures_equal(extensions=['png'])
def test_tight_layout_text(fig_test, fig_ref):
# text is currently ignored in tight layout. So the order of text() and
# tight_layout() calls should not influence the result.
ax1 = fig_test.gca(projection='3d')
ax1.text(.5, .5, .5, s='some string')
fig_test.tight_layout()

ax2 = fig_ref.gca(projection='3d')
fig_ref.tight_layout()
ax2.text(.5, .5, .5, s='some string')


@image_comparison(baseline_images=['scatter3d'], remove_text=True)
def test_scatter3d():
fig = plt.figure()
Expand Down
0