Cannot set nonpositive limits with log transform

mpl hates my guts today.

I'm developing an application for work and need to plot some spectra on a
logscale. I can recreate my problem with embedding_in_qt4, by replacing
MyDynamicMplCanvas.compute_initial_figure with this:

    def compute_initial_figure(self):
         self.axes.plot([0, 1, 2, 3], [1, 2, 0, 4], 'r')
         self.axes.set_yscale('log')

[...]
File "/usr/lib64/python2.5/site-packages/matplotlib-0.90.1_r3709-py2.5-linux-x86_64.egg/matplotlib/axes.py",
line 1664, in set_ylim
    raise ValueError('Cannot set nonpositive limits with log transform')
ValueError: Cannot set nonpositive limits with log transform

I get that error even if I modify the update figure function so there is no
possibility of zeros occuring in the data:

    def update_figure(self):
        # Build a list of 4 random integers between 0 and 10 (both inclusive)
        l = [ random.randint(0, 10) for i in xrange(4) ]

        l[l<=0]=1 # I love numpy
        self.axes.plot([1, 1, 2, 3], l, 'r')
        self.draw()

Anyone have any ideas? I think I have a bad case of gremlins.

Darren

I have tracked this back through axes.cla(), which is called when axes._hold
is False, to axis.cla(). axis.cla() resets the locators, but the transforms
are still set to mtrans.LOG10. Since plot is called by loglog, and semilog*,
it shouldn't be using any methods that modify locators. If cla() resets the
transforms, then the behavior of plot will be different, preserving log
transforms when hold is True, but changing to linear transforms when hold is
False.

I wonder if cla() is trying to do too much. Maybe the initial setting of
locators should be moved out of cla(), which is called by Axes.__init__, and
into Axis.__init__. Then calls to cla() will preserve the scaling, and the
behavior of plot() will be consistent, regardless of the whether hold is
enabled or not.

Darren

···

On Tuesday 14 August 2007 07:35:43 pm Darren Dale wrote:

I'm developing an application for work and need to plot some spectra on a
logscale. I can recreate my problem with embedding_in_qt4, by replacing
MyDynamicMplCanvas.compute_initial_figure with this:

    def compute_initial_figure(self):
         self.axes.plot([0, 1, 2, 3], [1, 2, 0, 4], 'r')
         self.axes.set_yscale('log')

[...]
File
"/usr/lib64/python2.5/site-packages/matplotlib-0.90.1_r3709-py2.5-linux-x86
_64.egg/matplotlib/axes.py", line 1664, in set_ylim
    raise ValueError('Cannot set nonpositive limits with log transform')
ValueError: Cannot set nonpositive limits with log transform

I get that error even if I modify the update figure function so there is no
possibility of zeros occuring in the data