FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix AxisLabel not picking up fontsize from set_ylabel in axisartist by Mr-Neutr0n · Pull Request #31155 · matplotlib/matplotlib · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
20 changes: 20 additions & 0 deletions lib/mpl_toolkits/axisartist/axis_artist.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ def __init__(self, *args, axis_direction="bottom", axis=None, **kwargs):
self._axis = axis
self._pad = 5
self._external_pad = 0 # in pixels
self._fontsize_from_default = True
LabelBase.__init__(self, *args, **kwargs)
self._fontsize_from_default = True
self.set_axis_direction(axis_direction)

def set_pad(self, pad):
Expand Down Expand Up @@ -377,6 +379,24 @@ def set_axis_direction(self, d):
self.set_default_alignment(d)
self.set_default_angle(d)

def set_fontsize(self, fontsize):
# docstring inherited
self._fontsize_from_default = False
super().set_fontsize(fontsize)

set_size = set_fontsize

def get_fontsize(self):
# docstring inherited
if self._fontsize_from_default and self._axis is not None:
try:
return self.get_ref_artist().get_fontsize()
except (IndexError, AttributeError):
pass
return super().get_fontsize()

get_size = get_fontsize

def get_color(self):
return self.get_attribute_from_ref_artist("color")

Expand Down
18 changes: 18 additions & 0 deletions lib/mpl_toolkits/axisartist/tests/test_axislines.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,21 @@ def test_subplotzero_ylabel():
ax.axis["left", "right", "bottom", "top"].set_visible(False)

zero_axis.set_axisline_style("->")


def test_label_fontsize_from_axes():
"""Test that AxisLabel inherits fontsize from the underlying axis label."""
fig = plt.figure()
ax = Subplot(fig, 1, 1, 1)
fig.add_subplot(ax)

# set_ylabel with fontsize should propagate to AxisLabel
ax.set_ylabel("Test", fontsize=20)
assert ax.axis["left"].label.get_fontsize() == 20

ax.set_ylabel("Test", fontsize=14)
assert ax.axis["left"].label.get_fontsize() == 14

# explicit set_fontsize on AxisLabel should override
ax.axis["left"].label.set_fontsize(30)
assert ax.axis["left"].label.get_fontsize() == 30
Loading

Back | FazBrowse Home | New Git URL