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 ad76c83

Browse filesBrowse files
authored
Merge pull request #16896 from anntzer/offset-text-follows-tick-label-visibility
set_tick_params(label1On=False) should also make offset text invisible.
2 parents d5f3e26 + 1986da3 commit ad76c83
Copy full SHA for ad76c83

File tree

Expand file treeCollapse file tree

3 files changed

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

3 files changed

+20
-1
lines changed

‎doc/api/next_api_changes/behaviour.rst

Copy file name to clipboardExpand all lines: doc/api/next_api_changes/behaviour.rst
+5Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.py
+5-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+10Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.