Skip to content

scrub kwarg and use one figure for all of the tests #56

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
documented new scrub kwarg for clf
  • Loading branch information
ivanov committed Mar 24, 2011
commit aecc1e235f2aa7ef4328deee3306f8d952379972
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2011-03-23 New scrub kwarg for clf, which allows for the resetting
of the subplot parameters of a figure, and is backed back
a new rcParam which can restore the old default behavior.
Also fixed a huge memory leak in the test suite where
none of the generated figures were being closed or
cleared. - PI

2011-03-10 Update pytz version to 2011c, thanks to Simon Cross. - JKS

2011-03-06 Add standalone tests.py test runner script. - JKS
Expand Down
11 changes: 11 additions & 0 deletions doc/api/api_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ This chapter is a log of changes to matplotlib that affect the
outward-facing API. If updating matplotlib breaks your scripts, this
list may help describe what changes may be necessary in your code.

Changes beyond 1.0.1
====================

* The :meth:`matplotlib.figure.Figure.clf` and
:meth:`matplotlib.pyplot.clf` methods now accept a *scrub* kwarg.
Passing ``scrub=True`` will reset the figure's subplot parameters,
``scrub=False`` will clear the figure without touching the subplot
parameters(old behavior) and the default value of ``scrub=None`` will
set ``scrub`` to the value of ``rcParams['figure.autoscrub']``
(default).

Changes beyond 0.99.x
=====================

Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ def clf(self, keep_observers=False, scrub=None):
subplotparameters to the defaults.

If *scrub* is None, the behavior it will be set to
rcParams['figure.scrub'].
rcParams['figure.autoscrub'].
Copy link
Member

Choose a reason for hiding this comment

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

IMHO the rc parameter is overkill. We could default to False and let users who like the scrubbing clear define an alias def scrub(): clf(scrub=True), or we could even define it for them.

Copy link
Member Author

Choose a reason for hiding this comment

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

the reason I went with the kwarg is because I think users would have a reasonable expectation to have the clear figure command to clear the figure completely, as opposed to having to call a separate command for doing that. But given that others might want to keep the old behavior, we can leave as a user configurable option. The new default behavior (figure.autoscrub = True) allows for the plt.clf() commands to stay as is in the rest of the pull request (though I realize you don't like the code duplication).

"""
self.suppressComposite = None
self.callbacks = cbook.CallbackRegistry(('dpi_changed', ))
Expand All @@ -808,12 +808,11 @@ def clf(self, keep_observers=False, scrub=None):
self._axobservers = []

if scrub is None:
scrub = rcParams['figure.scrub']
scrub = rcParams['figure.autoscrub']
if scrub == True:
sp = self.subplotpars
sp.left = sp.right = sp.top = sp.bottom = sp.validate = None
sp.update()
self._cachedRenderer = None


def clear(self, keep_observers=False, scrub=None):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def __call__(self, s):
'figure.facecolor' : [ '0.75', validate_color], # facecolor; scalar gray
'figure.edgecolor' : [ 'w', validate_color], # edgecolor; white
'figure.autolayout' : [ False, validate_autolayout],
'figure.scrub' : [ True , validate_bool], # scrub subplotparams on clf
'figure.autoscrub' : [ True , validate_bool], # default behavior of scrub for clf()

'figure.subplot.left' : [0.125, ValidateInterval(0, 1, closedmin=True, closedmax=True)],
'figure.subplot.right' : [0.9, ValidateInterval(0, 1, closedmin=True, closedmax=True)],
Expand Down
1 change: 1 addition & 0 deletions matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ backend : %(backend)s
#figure.dpi : 80 # figure dots per inch
#figure.facecolor : 0.75 # figure facecolor; 0.75 is scalar gray
#figure.edgecolor : white # figure edgecolor
#figure.autoscrub : True # default figure.clf() behaviour

# The figure subplot parameters. All dimensions are fraction of the
# figure width or height
Expand Down