loglog plot problem

I can't seem to get loglog plots to work. Attached is a dump of ipython showing what I tried and what happened. In case you don't want to wade through this, just try the following:

hold(False)
x=arange(25)+1
loglog(x,x**2) # throws error
close(1)
plot(log(x),log(x**2)) # works
close(1)
plot(x,x**2)
plot(log(x),log(x**2)) # throws error
loglog(x,x**2) # also throws error

Here's a result of doing something similar to the above manually, with traceback:

freyer:~> ipython -pylab
Python 2.3.4 (#1, Feb 2 2005, 12:11:53)
Type "copyright", "credits" or "license" for more information.

IPython 0.6.7 -- An enhanced Interactive Python.
? -> Introduction to IPython's features.
%magic -> Information about IPython's 'magic' % functions.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

  Welcome to pylab, a matplotlib-based Python environment
    help(matplotlib) -> generic matplotlib information
    help(pylab) -> matlab-compatible commands from matplotlib
    help(plotting) -> plotting commands

In [1]: x=arange(10)+1

In [2]: plot(x,x**2)
Out[2]: [<matplotlib.lines.Line2D instance at 0x410f132c>]

In [3]: loglog(x,x**2)

···

---------------------------------------------------------------------------
exceptions.ValueError Traceback (most recent call last)

/home/swalton/<console>

/usr/lib/python2.3/site-packages/matplotlib/pylab.py in loglog(*args, **kwargs)
   1869 hold(b)
   1870 else:
-> 1871 draw_if_interactive()
   1872
   1873 hold(b)

/usr/lib/python2.3/site-packages/IPython/genutils.py in wrapper(*args, **kw)
    686 def wrapper(*args,**kw):
    687 wrapper.called = False
--> 688 out = func(*args,**kw)
    689 wrapper.called = True
    690 return out

/usr/lib/python2.3/site-packages/matplotlib/backends/__init__.py in draw_if_interactive()
     39 def draw_if_interactive():
     40 draw_if_interactive._called = True
---> 41 __draw_int()
     42 # Flag to store state, so external callers (like ipython) can keep track
     43 # of draw calls.

/usr/lib/python2.3/site-packages/matplotlib/backends/backend_tkagg.py in draw_if_interactive()
     56 figManager = Gcf.get_active()
     57 if figManager is not None:
---> 58 figManager.show()
     59
     60

/usr/lib/python2.3/site-packages/matplotlib/backends/backend_tkagg.py in show(self)
    275 # anim.py requires this
    276 if sys.platform=='win32' : self.window.update()
--> 277 else: self.canvas.draw()
    278 self._shown = True
    279

/usr/lib/python2.3/site-packages/matplotlib/backends/backend_tkagg.py in draw(self)
    140
    141 def draw(self):
--> 142 FigureCanvasAgg.draw(self)
    143 tkagg.blit(self._tkphoto, self.renderer._renderer, 2)
    144 self._master.update_idletasks()

/usr/lib/python2.3/site-packages/matplotlib/backends/backend_agg.py in draw(self)
    306 self.renderer = RendererAgg(w, h, self.figure.dpi)
    307 self._lastKey = key
--> 308 self.figure.draw(self.renderer)
    309
    310 def tostring_rgb(self):

/usr/lib/python2.3/site-packages/matplotlib/figure.py in draw(self, renderer)
    332
    333 # render the axes
--> 334 for a in self.axes: a.draw(renderer)
    335
    336 # render the figure text

/usr/lib/python2.3/site-packages/matplotlib/axes.py in draw(self, renderer)
   1167 if not self.get_visible(): return
   1168 renderer.open_group('axes')
-> 1169 self.transData.freeze() # eval the lazy objects
   1170 self.transAxes.freeze() # eval the lazy objects
   1171 if self.axison:

ValueError: Cannot take log of nonpositive value

In [4]: plot(log(x),log(x**2))
---------------------------------------------------------------------------
exceptions.ValueError Traceback (most recent call last)

/home/swalton/<console>

/usr/lib/python2.3/site-packages/matplotlib/pylab.py in plot(*args, **kwargs)
   1957 hold(b)
   1958 else:
-> 1959 draw_if_interactive()
   1960
   1961 hold(b)

/usr/lib/python2.3/site-packages/IPython/genutils.py in wrapper(*args, **kw)
    686 def wrapper(*args,**kw):
    687 wrapper.called = False
--> 688 out = func(*args,**kw)
    689 wrapper.called = True
    690 return out

/usr/lib/python2.3/site-packages/matplotlib/backends/__init__.py in draw_if_interactive()
     39 def draw_if_interactive():
     40 draw_if_interactive._called = True
---> 41 __draw_int()
     42 # Flag to store state, so external callers (like ipython) can keep track
     43 # of draw calls.

/usr/lib/python2.3/site-packages/matplotlib/backends/backend_tkagg.py in draw_if_interactive()
     56 figManager = Gcf.get_active()
     57 if figManager is not None:
---> 58 figManager.show()
     59
     60

/usr/lib/python2.3/site-packages/matplotlib/backends/backend_tkagg.py in show(self)
    275 # anim.py requires this
    276 if sys.platform=='win32' : self.window.update()
--> 277 else: self.canvas.draw()
    278 self._shown = True
    279

/usr/lib/python2.3/site-packages/matplotlib/backends/backend_tkagg.py in draw(self)
    140
    141 def draw(self):
--> 142 FigureCanvasAgg.draw(self)
    143 tkagg.blit(self._tkphoto, self.renderer._renderer, 2)
    144 self._master.update_idletasks()

/usr/lib/python2.3/site-packages/matplotlib/backends/backend_agg.py in draw(self)
    306 self.renderer = RendererAgg(w, h, self.figure.dpi)
    307 self._lastKey = key
--> 308 self.figure.draw(self.renderer)
    309
    310 def tostring_rgb(self):

/usr/lib/python2.3/site-packages/matplotlib/figure.py in draw(self, renderer)
    332
    333 # render the axes
--> 334 for a in self.axes: a.draw(renderer)
    335
    336 # render the figure text

/usr/lib/python2.3/site-packages/matplotlib/axes.py in draw(self, renderer)
   1167 if not self.get_visible(): return
   1168 renderer.open_group('axes')
-> 1169 self.transData.freeze() # eval the lazy objects
   1170 self.transAxes.freeze() # eval the lazy objects
   1171 if self.axison:

ValueError: Cannot take log of nonpositive value

In [5]: close(1)

In [6]: plot(log(x),log(x**2))
Out[6]: [<matplotlib.lines.Line2D instance at 0x4154094c>]

In [7]: close(1)

In [8]: loglog(x,x**2)
Out[8]: [<matplotlib.lines.Line2D instance at 0x4168570c>]

In [9]: Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.3/lib-tk/Tkinter.py", line 1345, in __call__
    return self.func(*args)
  File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_tkagg.py", line 139, in resize
    self.show()
  File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_tkagg.py", line 142, in draw
    FigureCanvasAgg.draw(self)
  File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_agg.py", line 308, in draw
    self.figure.draw(self.renderer)
  File "/usr/lib/python2.3/site-packages/matplotlib/figure.py", line 334, in draw
    for a in self.axes: a.draw(renderer)
  File "/usr/lib/python2.3/site-packages/matplotlib/axes.py", line 1169, in draw self.transData.freeze() # eval the lazy objects
ValueError: Cannot take log of nonpositive value

Stephen Walton wrote:

I can't seem to get loglog plots to work. Attached is a dump of ipython showing what I tried and what happened. In case you don't want to wade through this, just try the following:

hold(False)
x=arange(25)+1
loglog(x,x**2) # throws error
close(1)
plot(log(x),log(x**2)) # works
close(1)
plot(x,x**2)
plot(log(x),log(x**2)) # throws error
loglog(x,x**2) # also throws error

This works fine, but only with current CVS. I've been giving John a ton of nasty tests for log plotting, and he's fixed most problems. I do still have a dataset which causes an abort in the C++ extension code, but he's looking into it already. So in short, if you update to CVS, most of your log problems will be fixed. And John should have the last remaining nasty killed soon.

Additionally, CVS has dramatic performance improvements in several areas, noticeable mostly for plots with many elements.

Best,

f