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

Skip to content

Commit 1986da3

Browse files
committed
set_tick_params(label1On=False) should also make offset text invisible.
1 parent b31d64c commit 1986da3

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

doc/api/next_api_changes/behaviour.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,8 @@ using :rc:`keymap.quit_all`.
133133
Autoscale for arrow
134134
~~~~~~~~~~~~~~~~~~~
135135
Calling ax.arrow() will now autoscale the axes.
136+
137+
``set_tick_params(label1On=False)`` now also makes the offset text (if any) invisible
138+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
139+
... because the offset text can rarely be interpreted without tick labels
140+
anyways.

lib/matplotlib/axis.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,11 @@ def set_tick_params(self, which='major', reset=False, **kw):
824824
self._minor_tick_kw.update(kwtrans)
825825
for tick in self.minorTicks:
826826
tick._apply_params(**kwtrans)
827-
# special-case label color to also apply to the offset text
827+
# labelOn and labelcolor also apply to the offset text.
828+
if 'label1On' in kwtrans or 'label2On' in kwtrans:
829+
self.offsetText.set_visible(
830+
self._major_tick_kw.get('label1On', False)
831+
or self._major_tick_kw.get('label2On', False))
828832
if 'labelcolor' in kwtrans:
829833
self.offsetText.set_color(kwtrans['labelcolor'])
830834

lib/matplotlib/tests/test_axes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5497,6 +5497,16 @@ def test_offset_label_color():
54975497
assert ax.yaxis.get_offset_text().get_color() == 'red'
54985498

54995499

5500+
def test_offset_text_visible():
5501+
fig = plt.figure()
5502+
ax = fig.add_subplot(1, 1, 1)
5503+
ax.plot([1.01e9, 1.02e9, 1.03e9])
5504+
ax.yaxis.set_tick_params(label1On=False, label2On=True)
5505+
assert ax.yaxis.get_offset_text().get_visible()
5506+
ax.yaxis.set_tick_params(label2On=False)
5507+
assert not ax.yaxis.get_offset_text().get_visible()
5508+
5509+
55005510
def test_large_offset():
55015511
fig, ax = plt.subplots()
55025512
ax.plot((1 + np.array([0, 1.e-12])) * 1.e27)

0 commit comments

Comments
 (0)