## [Matplotlib-users] Problem with semilog and low number

 [Matplotlib-users] Problem with semilog and low number From: Jean-Baptiste Cazier - 2004-01-30 23:16:11 ```S=E6ll ! I am trying to plot very small number for the Y-axis on semilogy but they d= o not appear at all unless one of the value is higher Moreover the 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 [] >> semilogy([1.0, 2.3, 3.3],[9.4e-04, 9.4e-05, 9.4e-05]) <--- work [] Should I use a specific "long" definition of my floating number ? Takk Jean-Baptiste --=20 ----------------------------- Jean-Baptiste.Cazier@... Department of Statistics deCODE genetics Sturlugata,8 570 2993 101 Reykjav=EDk ```

 [Matplotlib-users] Problem with semilog and low number From: Jean-Baptiste Cazier - 2004-01-30 23:16:11 ```S=E6ll ! I am trying to plot very small number for the Y-axis on semilogy but they d= o not appear at all unless one of the value is higher Moreover the 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 [] >> semilogy([1.0, 2.3, 3.3],[9.4e-04, 9.4e-05, 9.4e-05]) <--- work [] Should I use a specific "long" definition of my floating number ? Takk Jean-Baptiste --=20 ----------------------------- Jean-Baptiste.Cazier@... Department of Statistics deCODE genetics Sturlugata,8 570 2993 101 Reykjav=EDk ```
 Re: [Matplotlib-users] Problem with semilog and low number From: John Hunter - 2004-02-04 03:17:23 ```>>>>> "Jean-Baptiste" =3D=3D Jean-Baptiste Cazier 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> [] >>> semilogy([1.0, 2.3, 3.3],[9.4e-04, 9.4e-05, 9.4e-05]) <--- >>> work Jean-Baptiste> [] 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 ```