## Re: [Matplotlib-users] Forcing full value on axis (Dave Simpson)

 Re: [Matplotlib-users] Forcing full value on axis (Dave Simpson) From: David Simpson - 2007-04-25 06:59:59 ```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 ```

 Re: [Matplotlib-users] Forcing full value on axis (Dave Simpson) From: David Simpson - 2007-04-25 06:59:59 ```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 ```
 Re: [Matplotlib-users] Forcing full value on axis (Dave Simpson) From: KrishnaPribadi - 2010-04-15 20:56:30 ```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@... > 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-%28Dave-Simpson%29-tp10175415p28260517.html Sent from the matplotlib - users mailing list archive at Nabble.com. ```
 Re: [Matplotlib-users] Forcing full value on axis (Dave Simpson) From: Friedrich Romstedt - 2010-04-17 17:08:40 ```2010/4/15 KrishnaPribadi : > 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 ```