Problem with plots being appended

Hi, I am using pylab to plot several graphs. One graph

    > appears in one class where I do the following:

    > plot_date(date, y, 'g-o') savefig(path, dpi=75)

    > Later on, in a different class, I do the a similar call:

    > plot_date(d, z, 'b-') savefig(path, dpi=75)

    > My problem is that the second call to plot_date simply
    > appends the new line to the original graph and I am not
    > sure why since the new graph also has new axis and a new
    > label.

    > It seems that the problem can be solved by calling
    > hold(False) after plotting the first line. Yet, I would
    > think that when I call the plot command in a separate class
    > and set up the axis labels, etc. that it would
    > automatically create a new set of axis, not append to the
    > existing saved file.

    > Is there something I should know? I would appreciate any
    > feedback on this matter.

matplotlib has no idea whether you call functions from separate
classes or not. The concept of the current figure is a pylab
construct, and if you don't like it you can be more explicit about
figure and construction and management. Here is a snippet using pylab

class A:
   def __init__(self):
      self.fig = figure()
      self.ax = self.fig.add_subplot(111)

   def makeplot(self):
      self.ax.plot([1,2,3])

class B:
   def __init__(self):
      self.fig = figure()
      self.ax = self.fig.add_subplot(111)

   def makeplot(self):
      self.ax.imshow(rand(100,100))

Here you do not use the "current figure" or "current axes" of the
pylab interface because you explicitly make calls on the figure and
axes objects in their respective classes.

For even more fine grained control, you can avoid pylab altogether and
use the API as described at
http://matplotlib.sourceforge.net/faq.html#OO

Hope this helps,
JDH