🌐 AI搜索 & 代理 主页
Skip to content
Open
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
16 changes: 8 additions & 8 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ def sharey(self, other):
self.set_ylim(y0, y1, emit=False, auto=other.get_autoscaley_on())
self.yaxis._scale = other.yaxis._scale

def __clear(self):
def __clear(self, **kwargs):
"""Clear the Axes."""
# The actual implementation of clear() as long as clear() has to be
# an adapter delegating to the correct implementation.
Expand All @@ -1279,7 +1279,7 @@ def __clear(self):
yaxis_visible = self.yaxis.get_visible()

for axis in self._axis_map.values():
axis.clear() # Also resets the scale to linear.
axis.clear(**kwargs) # Also resets the scale to linear.
for spine in self.spines.values():
spine._clear() # Use _clear to not clear Axis again

Expand Down Expand Up @@ -1389,23 +1389,23 @@ def __clear(self):

self.stale = True

def clear(self):
def clear(self, **kwargs):
"""Clear the Axes."""
# Act as an alias, or as the superclass implementation depending on the
# subclass implementation.
if self._subclass_uses_cla:
self.cla()
self.cla(**kwargs)
else:
self.__clear()
self.__clear(**kwargs)

def cla(self):
def cla(self, **kwargs):
"""Clear the Axes."""
# Act as an alias, or as the superclass implementation depending on the
# subclass implementation.
if self._subclass_uses_cla:
self.__clear()
self.__clear(**kwargs)
else:
self.clear()
self.clear(**kwargs)

class ArtistList(Sequence):
"""
Expand Down
40 changes: 29 additions & 11 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ def _reset_minor_tick_kw(self):
mpl.rcParams['axes.grid'] and
mpl.rcParams['axes.grid.which'] in ('both', 'minor'))

def clear(self):
def clear(self, **kwargs):
"""
Clear the axis.

Expand All @@ -860,17 +860,35 @@ def clear(self):
- major and minor grid
- units
- registered callbacks
"""
self.label._reset_visual_defaults()
# The above resets the label formatting using text rcParams,
# so we then update the formatting using axes rcParams
self.label.set_color(mpl.rcParams['axes.labelcolor'])
self.label.set_fontsize(mpl.rcParams['axes.labelsize'])
self.label.set_fontweight(mpl.rcParams['axes.labelweight'])
self.offsetText._reset_visual_defaults()
self.labelpad = mpl.rcParams['axes.labelpad']

self._init()
If no *kwargs* are passed *'reset'* is set by default to *False*.

When *'reset'* is set to *False*, part of the formatting of the axis
(labels and relative properties) is left unchanged. Thus, a "soft"
clear is executed in this case.
"""
if len(kwargs) > 1:
_log.debug(
"Method 'clear' can accept only one argument")
if 'reset' in kwargs:
reset = kwargs.pop('reset')
else:
reset = False # Default
if type(reset) is not bool:
reset = False # Default
_log.debug(
"kwarg 'reset' must be a bool. It will be set to False")
if reset:
self.label._reset_visual_defaults()
# The above resets the label formatting using text rcParams,
# so we then update the formatting using axes rcParams
self.label.set_color(mpl.rcParams['axes.labelcolor'])
self.label.set_fontsize(mpl.rcParams['axes.labelsize'])
self.label.set_fontweight(mpl.rcParams['axes.labelweight'])
self.offsetText._reset_visual_defaults()
self.labelpad = mpl.rcParams['axes.labelpad']

self._init()

self._set_scale('linear')

Expand Down