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
20 changes: 19 additions & 1 deletion lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,11 @@ def clear(self):

This does not reset tick and tick label visibility.
"""
self.label._reset_visual_defaults()
self.offsetText._reset_visual_defaults()
self.labelpad = mpl.rcParams['axes.labelpad']

self.label.set_text('') # self.set_label_text would change isDefault_
self._init()

self._set_scale('linear')

Expand Down Expand Up @@ -2193,6 +2196,13 @@ class XAxis(Axis):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._init()

def _init(self):
"""
Initialize the label and offsetText instance values and
`label_position` / `offset_text_position`.
"""
# x in axes coords, y in display coords (to be updated at draw time by
# _update_label_positions and _update_offset_text_position).
self.label.set(
Expand All @@ -2202,6 +2212,7 @@ def __init__(self, *args, **kwargs):
self.axes.transAxes, mtransforms.IdentityTransform()),
)
self.label_position = 'bottom'

self.offsetText.set(
x=1, y=0,
verticalalignment='top', horizontalalignment='right',
Expand Down Expand Up @@ -2444,6 +2455,13 @@ class YAxis(Axis):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._init()

def _init(self):
"""
Initialize the label and offsetText instance values and
`label_position` / `offset_text_position`.
"""
# x in display coords, y in axes coords (to be updated at draw time by
# _update_label_positions and _update_offset_text_position).
self.label.set(
Expand Down
34 changes: 33 additions & 1 deletion lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,39 @@ def __init__(self,
super().__init__()
self._x, self._y = x, y
self._text = ''
self._reset_visual_defaults(
text=text,
color=color,
fontproperties=fontproperties,
usetex=usetex,
parse_math=parse_math,
wrap=wrap,
verticalalignment=verticalalignment,
horizontalalignment=horizontalalignment,
multialignment=multialignment,
rotation=rotation,
transform_rotates_text=transform_rotates_text,
linespacing=linespacing,
rotation_mode=rotation_mode,
)
self.update(kwargs)

def _reset_visual_defaults(
self,
text='',
color=None,
fontproperties=None,
usetex=None,
parse_math=None,
wrap=False,
verticalalignment='baseline',
horizontalalignment='left',
multialignment=None,
rotation=None,
transform_rotates_text=False,
linespacing=None,
rotation_mode=None,
):
self.set_text(text)
self.set_color(
color if color is not None else mpl.rcParams["text.color"])
Expand All @@ -183,7 +216,6 @@ def __init__(self,
linespacing = 1.2 # Maybe use rcParam later.
self.set_linespacing(linespacing)
self.set_rotation_mode(rotation_mode)
self.update(kwargs)

def update(self, kwargs):
# docstring inherited
Expand Down