behaviour of clf()

Hey everyone,

Michael D and I are working on reducing the memory footprint of
our test suite here at Sage days (we've made very good progress!),
and came across a behavior of plt.clf() that we wanted feedback
on.

At the moment, plt.clf (i.e. fig.clf) do not clear all of the
state variable associated with a figure. I think the most
consistent thing to do is to have a clf() change the figure to be
the same as a freshly created plt.figure(), but this is not the
case. For example:

In [5]: f = plt.figure()

In [6]: f.subplotpars.left
Out[6]: 0.055

In [7]: f.subplotpars.left = .20

In [8]: f.clf()

In [9]: f.subplotpars.left
Out[9]: 0.20000000000000001

I propose making clf revert all variables back to their rcParams
defaults (i.e. make it so that Out[9]: 0.055), and possibly
creating a new rcParam to allow individuals to preserve the old
behavior (in case people have code which relies on it, and prefer
it to stay the same). Additionally, we could have an optional
bolean parameter to clf, called 'scrub' or 'fresh' or something like
that, which would implement the rcParam specified behavior by
default, but allow users to scrub or not scrub on a call by call
basis.

Does anyone have any thoughts about this?

···

--
Paul Ivanov
314 address only used for lists, off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7

My feeling is that it should retain some properties such as the figure size. Imagine a case where one would be creating figures for saving that is made of multiple subplots:

fig = plt.figure(figsize=plt.figaspect(0.5))

for index, data in enumerate(datas) :
ax = fig.add_subplot(1, 2, 1)
ax.plot(data[0])
ax = fig.add_subplot(1, 2, 2)
ax.plot(data[1])
fig.savefig(“foo%d.png” % index)

fig.clf()

In this case, I think it would be reasonable to expect that the figure retains its size. Then again, maybe I am doing it wrong…

Just my 2 cents.
Ben Root

···

On Tue, Mar 22, 2011 at 3:58 PM, Paul Ivanov <pivanov314@…322…9…> wrote:

Hey everyone,

Michael D and I are working on reducing the memory footprint of

our test suite here at Sage days (we’ve made very good progress!),

and came across a behavior of plt.clf() that we wanted feedback

on.

At the moment, plt.clf (i.e. fig.clf) do not clear all of the

state variable associated with a figure. I think the most

consistent thing to do is to have a clf() change the figure to be

the same as a freshly created plt.figure(), but this is not the

case. For example:

In [5]: f = plt.figure()

In [6]: f.subplotpars.left

Out[6]: 0.055

In [7]: f.subplotpars.left = .20

In [8]: f.clf()

In [9]: f.subplotpars.left

Out[9]: 0.20000000000000001

I propose making clf revert all variables back to their rcParams

defaults (i.e. make it so that Out[9]: 0.055), and possibly

creating a new rcParam to allow individuals to preserve the old

behavior (in case people have code which relies on it, and prefer

it to stay the same). Additionally, we could have an optional

bolean parameter to clf, called ‘scrub’ or ‘fresh’ or something like

that, which would implement the rcParam specified behavior by

default, but allow users to scrub or not scrub on a call by call

basis.

Does anyone have any thoughts about this?