should the ordering of clf() matter for AxesGrid?

Given the code snippet below with clf() #1 uncommented works like one would expect - both plots are drawn. If #1 is commented out and #2 is uncommented, then the figure is cleared and neither plot is drawn. Is this the correct behavior? It seems like a bug to me.

M

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import AxesGrid

f = plt.figure(1)
plt.clf() #1
grid = AxesGrid(f, 111, (1,2))
#plt.clf() #2
grid[0].plot(np.arange(10))
grid[1].plot(np.arange(10))
plt.draw()

Hi Mike,

Mike Kaufman, on 2012-01-11 19:30, wrote:

Given the code snippet below with clf() #1 uncommented works like one
would expect - both plots are drawn. If #1 is commented out and #2 is
uncommented, then the figure is cleared and neither plot is drawn. Is
this the correct behavior? It seems like a bug to me.

Seems to me like this is the intended behavior and not a bug. I'm
not sure what you were expecting to happen with that second call
to clf. You're clearing the whole figure, so even though the
axes you have in the grid variable have references to f, f has
disowned them!

  In [39]: grid = AxesGrid(f, 111, (1,2))
  
  In [40]: f.axes
  Out[40]:
  [<mpl_toolkits.axes_grid1.axes_divider.LocatableAxes at 0xb7c002c>,
   <mpl_toolkits.axes_grid1.axes_divider.LocatableAxes at 0xb8948cc>,
   <mpl_toolkits.axes_grid1.axes_grid.CbarAxes at 0xb810dac>,
   <mpl_toolkits.axes_grid1.axes_grid.CbarAxes at 0xb97486c>]
  
  In [41]: plt.clf()
  
  In [42]: f.axes
  Out[42]:

Perhaps you wanted to simply to clear the individual axes? You
can do that with [g.cla() for g in grid] instead of your call to
plt.clf()

best,

···

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

Ok, this was my bad. I was under the [mistaken] impression (and in retrospect I'm not sure why) that the AxesGrid call just set up the geometry and the plot calls actually created the axes.

Thanks for setting me straight.

M

···

On 1/11/12 9:05 PM, Paul Ivanov wrote:

Hi Mike,

Mike Kaufman, on 2012-01-11 19:30, wrote:

Given the code snippet below with clf() #1 uncommented works like one
would expect - both plots are drawn. If #1 is commented out and #2 is
uncommented, then the figure is cleared and neither plot is drawn. Is
this the correct behavior? It seems like a bug to me.

Seems to me like this is the intended behavior and not a bug. I'm
not sure what you were expecting to happen with that second call
to clf. You're clearing the whole figure, so even though the
axes you have in the grid variable have references to f, f has
disowned them!

   In [39]: grid = AxesGrid(f, 111, (1,2))

   In [40]: f.axes
   Out[40]:
   [<mpl_toolkits.axes_grid1.axes_divider.LocatableAxes at 0xb7c002c>,
    <mpl_toolkits.axes_grid1.axes_divider.LocatableAxes at 0xb8948cc>,
    <mpl_toolkits.axes_grid1.axes_grid.CbarAxes at 0xb810dac>,
    <mpl_toolkits.axes_grid1.axes_grid.CbarAxes at 0xb97486c>]

   In [41]: plt.clf()

   In [42]: f.axes
   Out[42]:

Perhaps you wanted to simply to clear the individual axes? You
can do that with [g.cla() for g in grid] instead of your call to
plt.clf()

best,