8000 Fix: axis, ticks are set to defaults fontsize after ax.clear() (#21253) · matplotlib/matplotlib@c4082c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit c4082c1

Browse files
tsumlitsumlitsumli
authored
Fix: axis, ticks are set to defaults fontsize after ax.clear() (#21253)
* add: _reset_visual_defaults function in Text class * retrigger checks * refactor: Axis._init and Text.__init__ * bugfix: reset text to blank string in clear * refactor: set_tex 8000 t to reset_visual_defaults * refactor: delete unnecessary set_text in Axis.clear Co-authored-by: tsumli <sample@example.com> Co-authored-by: tsumli <example@example.com>
1 parent 39c997e commit c4082c1

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

lib/matplotlib/axis.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,11 @@ def clear(self):
895895
896896
This does not reset tick and tick label visibility.
897897
"""
898+
self.label._reset_visual_defaults()
899+
self.offsetText._reset_visual_defaults()
900+
self.labelpad = mpl.rcParams['axes.labelpad']
898901

899-
self.label.set_text('') # self.set_label_text would change isDefault_
902+
self._init()
900903

901904
self._set_scale('linear')
902905

@@ -2193,6 +2196,13 @@ class XAxis(Axis):
21932196

21942197
def __init__(self, *args, **kwargs):
21952198
super().__init__(*args, **kwargs)
2199+
self._init()
2200+
2201+
def _init(self):
2202+
"""
2203+
Initialize the label and offsetText instance values and
2204+
`label_position` / `offset_text_position`.
2205+
"""
21962206
# x in axes coords, y in display coords (to be updated at draw time by
21972207
# _update_label_positions and _update_offset_text_position).
21982208
self.label.set(
@@ -2202,6 +2212,7 @@ def __init__(self, *args, **kwargs):
22022212
self.axes.transAxes, mtransforms.IdentityTransform()),
22032213
)
22042214
self.label_position = 'bottom'
2215+
22052216
self.offsetText.set(
22062217
x=1, y=0,
22072218
verticalalignment='top', horizontalalignment='right',
@@ -2444,6 +2455,13 @@ class YAxis(Axis):
24442455

24452456
def __init__(self, *args, **kwargs):
24462457
super().__init__(*args, **kwargs)
2458+
self._init()
2459+
2460+
def _init(self):
2461+
"""
2462+
Initialize the label and offsetText instance values and
2463+
`label_position` / `offset_text_position`.
2464+
"""
24472465
# x in display coords, y in axes coords (to be updated at draw time by
24482466
# _update_label_positions and _update_offset_text_position).
24492467
self.label.set(

lib/matplotlib/text.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,39 @@ def __init__(self,
164164
super().__init__()
165165
self._x, self._y = x, y
166166
self._text = ''
167+
self._reset_visual_defaults(
168+
text=text,
169+
color=color,
170+
fontproperties=fontproperties,
171+
usetex=usetex,
172+
parse_math=parse_math,
173+
wrap=wrap,
174+
verticalalignment=verticalalignment,
175+
horizontalalignment=horizontalalignment,
176+
multialignment=multialignment,
177+
rotation=rotation,
178+
transform_rotates_text=transform_rotates_text,
179+
linespacing=linespacing,
180+
rotation_mode=rotation_mode,
181+
)
182+
self.update(kwargs)
183+
184+
def _reset_visual_defaults(
185+
self,
186+
text='',
187+
color=None,
188+
fontproperties=None,
189+
usetex=None,
190+
parse_math=None,
191+
wrap=False,
192+
verticalalignment='baseline',
193+
horizontalalignment='left',
194+
multialignment=None,
195+
rotation=None,
196+
transform_rotates_text=False,
197+
linespacing=None,
198+
rotation_mode=None,
199+
):
167200
self.set_text(text)
168201
self.set_color(
169202
color if color is not None else mpl.rcParams["text.color"])
@@ -1 667B 83,7 +216,6 @@ def __init__(self,
183216
linespacing = 1.2 # Maybe use rcParam later.
184217
self.set_linespacing(linespacing)
185218
self.set_rotation_mode(rotation_mode)
186-
self.update(kwargs)
187219

188220
def update(self, kwargs):
189221
# docstring inherited

0 commit comments

Comments
 (0)
0