Cannot set nonpositive limits with log transform

The other option is to do something sensible when axes limits are
negative on the log scale. We switch back and forth between linear and log
while zooming/panning. Since it is difficult to keep the limits positive
when using the linear scale we would love to have the plot handle bad
limits. I don't have a patch yet, but I don't mind if you beat me to it

Ultimately we would like negative data to be represented using
an inverted logarithmic scale, but this is a more difficult project.
For now we are masking out any data <= 0.

On Wed, Aug 15, 2007 at 09:57:21AM -0400, Darren Dale wrote:

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

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.

Thats a seperate, but important issue. In the case I described, the state of
the plot becomes a mash of log transforms and linear locators.

On Wednesday 15 August 2007 03:18:25 pm you wrote:

On Wed, Aug 15, 2007 at 09:57:21AM -0400, Darren Dale wrote:
> 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
>
> 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.

The other option is to do something sensible when axes limits are
negative on the log scale.