Axis problem demo program

View: New views
4 Messages — Rating Filter:   Alert me  

Axis problem demo program

by Jim Horning :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Greetings,

I've been having difficulties with axis limit control.  From a bigger application I've reduced an example down to the following short code segment.  Note, the commented-out line, #x = numpy.linspace(98.42, 99.21, 100), line in which the example works OKAY.

What is annoying is that the following example will produce a graph in which the x-axis is labeled at ticks starting at 0.1 going to 0.35 (times 1.474e2 !)  Instead, I am expecting an axis from 147.63 to 148.31.  Note that if you swap out the x with the commented-out line the example works like I would expect.

By the way, this example is with pylab.  However, I've got the same problem using plt from matplotlib or anything matplotlib related.
===

import random
import numpy
import pylab

#x = numpy.linspace(98.42, 99.21, 100)
x = numpy.linspace(147.63, 148.31, 100)
y = numpy.random.random((len(x)))
pylab.plot(x, y)
pylab.xlim(numpy.min(x), numpy.min(x))
pylab.show()


--
--------------------
Jim A. Horning
jim@...

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Re: Axis problem demo program

by Michael Droettboom-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jim Horning wrote:

> Greetings,
>
> I've been having difficulties with axis limit control.  From a bigger
> application I've reduced an example down to the following short code
> segment.  Note, the commented-out line, #x = numpy.linspace(98.42,
> 99.21, 100), line in which the example works OKAY.
>
> What is annoying is that the following example will produce a graph in
> which the x-axis is labeled at ticks starting at 0.1 going to 0.35
> (times 1.474e2 !)  Instead, I am expecting an axis from 147.63 to
> 148.31.  Note that if you swap out the x with the commented-out line
> the example works like I would expect.
First, a small bug in your example.  I think you meant:

pylab.xlim(numpy.min(x), numpy.min(x))

to be:

pylab.xlim(numpy.min(x), numpy.max(x))

In the former case, when you have "unity" limits, matplotlib adds a
small delta to the min and max so the range is not empty.

Once this is fixed, the notation is actually ~0.1 to ~0.8 *plus* (not
*times*) 1.474e2, which is at least correct, if not desired.  The reason
matplotlib does this is that, for space considerations, it avoids
displaying ticks with more than 4 significant digits.  Since the range
here is so small, it prints the "offset" in the lower right and adjusts
the ticks accordingly.  Unfortunately, this number of significant digits
isn't user customizable, though perhaps it should be (just as the range
for scientific notation is).  Can you file an enhancement request in the
tracker so this doesn't get lost?

Does anyone with more experience with the scientific notation/offset
code have any further comments?

Mike

>
> By the way, this example is with pylab.  However, I've got the same
> problem using plt from matplotlib or anything matplotlib related.
> ===
>
> import random
> import numpy
> import pylab
>
> #x = numpy.linspace(98.42, 99.21, 100)
> x = numpy.linspace(147.63, 148.31, 100)
> y = numpy.random.random((len(x)))
> pylab.plot(x, y)
> pylab.xlim(numpy.min(x), numpy.min(x))
> pylab.show()
>
>
> --
> --------------------
> Jim A. Horning
> jim@... <mailto:jim@...>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> ------------------------------------------------------------------------
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>  

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Re: Axis problem demo program

by Matthias Michler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Jim,

I attached an example that does the job circumventing Matplotlibs scientific
formatting instead of solving the problem with number of digits in scientific
formatting. It uses a FuncFormatter from matplotlib.ticker, which allows you
to define your own tick-formatting.

Kind regards
Matthias

On Wednesday 28 October 2009 11:16:54 Jim Horning wrote:

> Greetings,
>
> I've been having difficulties with axis limit control.  From a bigger
> application I've reduced an example down to the following short code
> segment.  Note, the commented-out line, #x = numpy.linspace(98.42, 99.21,
> 100), line in which the example works OKAY.
>
> What is annoying is that the following example will produce a graph in
> which the x-axis is labeled at ticks starting at 0.1 going to 0.35 (times
> 1.474e2 !)  Instead, I am expecting an axis from 147.63 to 148.31.  Note
> that if you swap out the x with the commented-out line the example works
> like I would expect.
>
> By the way, this example is with pylab.  However, I've got the same problem
> using plt from matplotlib or anything matplotlib related.
> ===
>
> import random
> import numpy
> import pylab
>
> #x = numpy.linspace(98.42, 99.21, 100)
> x = numpy.linspace(147.63, 148.31, 100)
> y = numpy.random.random((len(x)))
> pylab.plot(x, y)
> pylab.xlim(numpy.min(x), numpy.min(x))
> pylab.show()
>
>
> --
> --------------------
> Jim A. Horning
> jim@...



------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

axis_problem_demo_program.py (496 bytes) Download Attachment

Re: Axis problem demo program

by Jae-Joon Lee :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Oct 28, 2009 at 9:55 AM, Michael Droettboom <mdroe@...> wrote:
> Does anyone with more experience with the scientific notation/offset
> code have any further comments?

While it is possible to turn off using the offset (or setting it
manually), the api is not very friendly.

fmt = gca().xaxis.get_major_formatter()
fmt._useOffset = False
fmt.offset = 0

Regards,

-JJ

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users