From: Hans F. <H.F...@so...> - 2005-02-25 10:20:00
|
Hi John, > Hans> x=pylab.arange(0,1e-8,1e-9)+1.0 pylab.plot(x) pylab.show() > > Hans> All works fine when I subtract the mean of x but there seems > Hans> to be a problem with labelling axes for plotted data which > Hans> is not close to zero but shows only small variations. > > I agree it's a bug. It's not immediately clear to me what the labels > should be though > > 1.0000000002 > 1.0000000004 > 1.0000000006 > > and so on? That takes up a lot of room. Granted, correct but ugly > is better than incorrect but pretty, but I'm curious if there is a > better way to format these cases. Perhaps ideal would be an indicator > at the bottom or top of the y axis that read '1+' and then use 2e-9, > 4e-9, etc as the actual tick labels. Do you agree this is ideal? That would be very cool ;-) [but not soo easy to code I suppose]. I just checked what Matlab does (seeing that they have been in the business for a while), and if I run the equivalent program (i.e. plotting date from 1+0e-9, 1+1e-9, 1+2e-9,...,1e-8), the plot just shows "1" at each tick. So: yes, I agree with your suggested ideal solution but as long as Matlab doesn't do this and there is a workaround (as you show below), this is probably not a high-priority bug ;-) > To achieve this, as you may know, you can pass in a custom tick > formatter. Eg > > import pylab > > def myformatter(x, pos): > return '%1.0e'%(x-1) > > ax = pylab.subplot(111) > x=pylab.arange(0,1e-8,1e-9)+1.0 > ax.plot(x) > formatter = pylab.FuncFormatter(myformatter) > ax.yaxis.set_major_formatter(formatter) > ax.text(-.125, 1.025, '1+', transform=ax.transAxes) > pylab.show() > > See also examples/custom_ticker1.py. > > This is not to say that I don't want to fix this bug; I just wanted to > make sure you are aware of this workaround. That's very useful information -- I wasn't aware of this possibility and am sure it will be useful to others searching the mailing list for answers. Best wishes, Hans |