pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/matplotlib/matplotlib/commit/64ecd118ec2029da602bee9ee80e22d40d8317dd

.css" /> Let ticklabels respect set_in_layout(False). · matplotlib/matplotlib@64ecd11 · GitHub
Skip to content

Commit 64ecd11

Browse files
committed
Let ticklabels respect set_in_layout(False).
This is useful for manual finetuning of layout of static plots.
1 parent 1f8ff33 commit 64ecd11

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/matplotlib/axis.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,9 +1333,11 @@ def _update_ticks(self):
13331333
def _get_ticklabel_bboxes(self, ticks, renderer):
13341334
"""Return lists of bboxes for ticks' label1's and label2's."""
13351335
return ([tick.label1.get_window_extent(renderer)
1336-
for tick in ticks if tick.label1.get_visible()],
1336+
for tick in ticks
1337+
if tick.label1.get_visible() and tick.label1.get_in_layout()],
13371338
[tick.label2.get_window_extent(renderer)
1338-
for tick in ticks if tick.label2.get_visible()])
1339+
for tick in ticks
1340+
if tick.label2.get_visible() and tick.label2.get_in_layout()])
13391341

13401342
def get_tightbbox(self, renderer=None, *, for_layout_only=False):
13411343
"""

lib/matplotlib/tests/test_axis.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import matplotlib.pyplot as plt
44
from matplotlib.axis import XTick
5+
from matplotlib.testing.decorators import check_figures_equal
56

67

78
def test_tick_labelcolor_array():
@@ -31,6 +32,21 @@ def test_axis_not_in_layout():
3132
assert ax1_right.get_position().bounds == ax2_right.get_position().bounds
3233

3334

35+
@check_figures_equal()
36+
def test_tick_not_in_layout(fig_test, fig_ref):
37+
# Check that the "very long" ticklabel is ignored from layouting after
38+
# set_in_layout(False); i.e. the layout is as if the ticklabel was empty.
39+
# Ticklabels are set to white so that the actual string doesn't matter.
40+
fig_test.set_layout_engine("constrained")
41+
ax = fig_test.add_subplot(xticks=[0, 1], xticklabels=["short", "very long"])
42+
ax.tick_params(labelcolor="w")
43+
fig_test.draw_without_rendering() # Ensure ticks are correct.
44+
ax.xaxis.majorTicks[-1].label1.set_in_layout(False)
45+
fig_ref.set_layout_engine("constrained")
46+
ax = fig_ref.add_subplot(xticks=[0, 1], xticklabels=["short", ""])
47+
ax.tick_params(labelcolor="w")
48+
49+
3450
def test_translate_tick_params_reverse():
3551
fig, ax = plt.subplots()
3652
kw = {'label1On': 'a', 'label2On': 'b', 'tick1On': 'c', 'tick2On': 'd'}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy