>>>>> "Jean-Baptiste" =3D=3D Jean-Baptiste Cazier <Jean-Baptiste.cazier@d=
ecode.is> writes:
Jean-Baptiste> S=E6ll ! I am trying to plot very small number for
Jean-Baptiste> the Y-axis on semilogy but they do not appear at
Jean-Baptiste> all unless one of the value is higher Moreover the
Jean-Baptiste> labels on the Y axis become 0 below 0.001
>>> semilogy([1.0, 2.3, 3.3],[9.4e-05, 9.4e-05, 9.4e-05]) <-- does
>>> not work
Jean-Baptiste> [<matplotlib.lines.Line2D instance at 0x935255c>]
>>> semilogy([1.0, 2.3, 3.3],[9.4e-04, 9.4e-05, 9.4e-05]) <---
>>> work
Jean-Baptiste> [<matplotlib.lines.Line2D instance at 0x940e964>]
S=E6ll Jean!
Thanks for this example. The relevant code which handles autoscaling
is in matplotlib.axis.autoscale_view. I wasn't handling the special
case where min=3Dmax for log scaling (though I do handle it for linear
scaling).
Try this replacement code for axis.py: and the functions decade_down
and decade_up and replace the autoscale_view function.
def decade_down(x):
'floor x to the nearest lower decade'
lx =3D math.floor(math.log10(x))
return 10**lx
def decade_up(x):
'ceil x to the nearest higher decade'
lx =3D math.ceil(math.log10(x))
return 10**lx
class Axis(Artist):
def autoscale_view(self):
'Try to choose the view limits intelligently'
vmin, vmax =3D self.datalim.bounds()
if self._scale=3D=3D'linear':
if vmin=3D=3Dvmax:
vmin-=3D1
vmax+=3D1
try:
(exponent, remainder) =3D divmod(math.log10(vmax - vmin),=
1)
except OverflowError:
print >>sys.stderr, 'Overflow error in autoscale', vmin, =
vmax
return
if remainder < 0.5:
exponent -=3D 1
scale =3D 10**(-exponent)
vmin =3D math.floor(scale*vmin)/scale
vmax =3D math.ceil(scale*vmax)/scale
self.viewlim.set_bounds(vmin, vmax)
elif self._scale=3D=3D'log':
if vmin=3D=3Dvmax:
vmin =3D decade_down(vmin)
vmax =3D decade_up(vmax)
self.viewlim.set_bounds(vmin, vmax)
Let me know how this works for you,
JDH
|