On Thu, Jul 22, 2010 at 3:48 AM, alberttresens <albert.tres...@gmail.com> wrote:
>
> Might be usefull, that is the script I am trying to run. I has some checks,
> but is basiclly from Salmon Run Blog:

We can't run this because when you pasted the text into the browser it
was line wrapped and would require significant editing to make it
syntactically correct.  When posting code, it helps to attach it as
well to avoid these kinds of problems.  Also, the script requires a gc
logfile which we do not have, so for us to be able to run it we would
need the input as well.  It is much easier for us to debug code that
we can actually run.

So I will haxard a guess based on a quick inspection.  You are
probably running and rerunning this code in an environment with a
persistent python session, like Idle, ipython or some other IDE.  The
calls to "plot" you are making my default replot into the same figure
and axes, and that figure contains some bad data from an earlier run
that is messing subsequent runs up.  This problem should go away if
you run your script in a clean environment, eg from the shell command
line with a new python session.  Alternatively, in a running session,
just do

  plt.close('all')

to clear out all your old figures.

You can also insure that the plotting goes into a new figure by calling

  figure()

before any plotting commands.

It is usually a bad idea to rely on pyplot's manipulation of the
current figure and axes when embedding plotting code in a function,
since functions can be called in multiple contexts.  I usually use the
API, and the following idiom for writing plotting functions

def somefunc(x, y, fig=None):
    """
    plot x vs y.
    fig is a matplotlib Figure instance; if None create a new pyplot figure

    The Figure instance is returned
    """
    if fig is None:
        # we import pyplot here and not at the top level so that
        # people who are managing their own figures, eg in a user
        # interface application, will not trigger the pyplot user
        # interface code which coul cause conflicts
        import matplotlib.pyplot as plt
        fig = plt.figure()

    # we explicitly instantiate our axes rather than rely on pyplot's
    # stateful management of current figure and axes
    ax = fig.add_subplot(111)

    ax.plot(x, y)
    ax.set_title('x vs y')
    ax.set_xlabel('x')
    ax.set_ylabel('y')
    ax.grid(True)
    return fig

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to