Forcing full value on axis (Dave Simpson)

I also had some trouble with exponents in an axis, getting
0.0 to 3.0 on the axis, with +1.998e3. I wanted the years
1998 to 2001 instead. I solved this using the following code
(with the solution bits commented out):

#!/usr/bin/env python
from pylab import *
# from matplotlib.ticker import FormatStrFormatter

x = array([ 1998, 1999, 2000, 2001 ])
y = array([ 2.3, 4.5, 2.6, 7.2 ])

# ax=subplot(111)
plot(x,y)

## Needed to get 2001, not 1+2e3:
# majorFormatter=FormatStrFormatter('%d')
# ax.xaxis.set_major_formatter(majorFormatter)
# show()

Dave

I just tried this method and it does work if you are using integers or whole
numbers. However, I am working with time on my x axis. So when I zoom too
close, floating point numbers are required... Is there any way to just turn
off the exponent number in the right corner and force the x tick labels to
be integers or floating point depending on how close one is zoomed?

David Simpson-3 wrote:

ยทยทยท

I also had some trouble with exponents in an axis, getting
0.0 to 3.0 on the axis, with +1.998e3. I wanted the years
1998 to 2001 instead. I solved this using the following code
(with the solution bits commented out):

#!/usr/bin/env python
from pylab import *
# from matplotlib.ticker import FormatStrFormatter

x = array([ 1998, 1999, 2000, 2001 ])
y = array([ 2.3, 4.5, 2.6, 7.2 ])

# ax=subplot(111)
plot(x,y)

## Needed to get 2001, not 1+2e3:
# majorFormatter=FormatStrFormatter('%d')
# ax.xaxis.set_major_formatter(majorFormatter)
# show()

Dave

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

-----
Krishna Adrianto Pribadi
Test Engineer
Harley-Davidson Motor Co.
Talladega Test Facility
Vehicle Test Stands
--
View this message in context: http://old.nabble.com/Re%3A-Forcing-full-value-on-axis-(Dave-Simpson)-tp10175415p28260517.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

2010/4/15 KrishnaPribadi <Krishna.Pribadi@...3019...>:

Is there any way to just turn
off the exponent number in the right corner and force the x tick labels to
be integers or floating point depending on how close one is zoomed?

Have a look at matplotlib/ticker.py. Most classes in ticker.py are
derived from class ticker.TickHelper. This in turn has a method
.set_axis(). So I think when you write your own formatter class, you
should be able to make use of this, because I guess it's called upon
attachment of the formatter to the axis, by the axis instance it's
attached to. This means, you should be able to retrieve the view
limits from the .axis attribute during __call__() of the formatter, so
you can choose the format used appropriate according to the view span.

Maybe, just as a thought, you should also have a look at the Locator
class you're using, to find out how the decision is made, when to use
integer tick positions and when to use fp ones.

I think you should derive your formatter class from class ticker.Formatter.

hth,
Friedrich