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

Skip to content

Fix: axis, ticks are set to defaults fontsize after ax.clear() #21253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 11 additions & 1 deletion lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,11 @@ def clear(self):
This does not reset tick and tick label visibility.
"""

self.label.set_text('') # self.set_label_text would change isDefault_
self.label._reset_visual_defaults()
self.offsetText._reset_visual_defaults()
self.labelpad = mpl.rcParams['axes.labelpad']

self._set_default()

self._set_scale('linear')

Expand Down Expand Up @@ -2193,6 +2197,9 @@ class XAxis(Axis):

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

def _set_default(self):
# 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 Down Expand Up @@ -2444,6 +2451,9 @@ class YAxis(Axis):

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

def _set_default(self):
# 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: 34 additions & 0 deletions lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,40 @@ def __init__(self,
"""
super().__init__()
self._x, self._y = x, y
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,
**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,
**kwargs,
):
self._text = ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this line to __init__ (this is just for creating the argument, set_text updates it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also thnik that self.update doesn't really belong in _reset...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your review @oscargus ! but I'm a bit comfused about the first comment.
You mean remove _rest_visual_defaults in Text should be removed and the following lines (ll 200-) are moved in __init__ right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry.

I meant that the lines self._text = '' and self.update(**kwargs) should be moved to __init__,

so something like:

self._text = ''
self._reset_visual_defaults(...)  # without kwargs
self.update(kwargs)

self.set_text(text)
self.set_color(
Expand Down
0