Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
6 changes: 4 additions & 2 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1333,9 +1333,11 @@ def _update_ticks(self):
def _get_ticklabel_bboxes(self, ticks, renderer):
"""Return lists of bboxes for ticks' label1's and label2's."""
return ([tick.label1.get_window_extent(renderer)
for tick in ticks if tick.label1.get_visible()],
for tick in ticks
if tick.label1.get_visible() and tick.label1.get_in_layout()],
[tick.label2.get_window_extent(renderer)
for tick in ticks if tick.label2.get_visible()])
for tick in ticks
if tick.label2.get_visible() and tick.label2.get_in_layout()])

def get_tightbbox(self, renderer=None, *, for_layout_only=False):
"""
Expand Down
16 changes: 16 additions & 0 deletions lib/matplotlib/tests/test_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import matplotlib.pyplot as plt
from matplotlib.axis import XTick
from matplotlib.testing.decorators import check_figures_equal


def test_tick_labelcolor_array():
Expand Down Expand Up @@ -31,6 +32,21 @@ def test_axis_not_in_layout():
assert ax1_right.get_position().bounds == ax2_right.get_position().bounds


@check_figures_equal()
def test_tick_not_in_layout(fig_test, fig_ref):
# Check that the "very long" ticklabel is ignored from layouting after
# set_in_layout(False); i.e. the layout is as if the ticklabel was empty.
# Ticklabels are set to white so that the actual string doesn't matter.
fig_test.set_layout_engine("constrained")
ax = fig_test.add_subplot(xticks=[0, 1], xticklabels=["short", "very long"])
ax.tick_params(labelcolor="w")
fig_test.draw_without_rendering() # Ensure ticks are correct.
ax.xaxis.majorTicks[-1].label1.set_in_layout(False)
fig_ref.set_layout_engine("constrained")
ax = fig_ref.add_subplot(xticks=[0, 1], xticklabels=["short", ""])
ax.tick_params(labelcolor="w")


def test_translate_tick_params_reverse():
fig, ax = plt.subplots()
kw = {'label1On': 'a', 'label2On': 'b', 'tick1On': 'c', 'tick2On': 'd'}
Expand Down
Loading