Re: [Matplotlib-users] scientific notation in ticklabels for linear plot

2010-10-19 Thread Friedrich Romstedt
2010/10/18 Jonathan Slavin jsla...@cfa.harvard.edu:
 I'm wondering if there's some relatively automatic way to have the
 ticklabels to come out in scientific notation for an axis that uses a
 linear scale (and has a range that warrants scientific notation)?  For
 example, an axis that goes from 0 to 2.E18 by default uses the labels 0,
 0.5, 1.0, 1.5, 2.0 and puts 1e18 at the end of the axis.  To me this is
 unappealing. 1e18 is a computer programming way to write the 10^{18} (in
 LaTeX formatting).  In IDL the ticklabels are 5.0x10^{17}, 1.0x10^{18},
 1.5x10^{18}, 2.0x10^{18}.  This is one instance where I think IDL gets
 it right and matplotlib gets it wrong.  So, as far as I can tell, one
 can give the ticklabels by hand, and so I could achieve my desired
 labels that way, but it'd be nice to have a more automatic way to do it.
 Searching the examples, I've come up empty so far.  I would also
 advocate changing the default format for labeling axes that fall in this
 category.  Do the developers have any opinions on this?

There's a thread some monthes ago about this, I provided code to do
this.  Currently, this Formatter class didn't make it into matplotlib
due a lack of providing a patch by me.  If others agree that this
would be a good feature, I'll clean the code if necessary and provide
another patch for this.

Looking for the thread ...
http://article.gmane.org/gmane.comp.python.matplotlib.general/23824/match=scientific+notation+friedrich

IIRC, the formatter class does NOT provide automatic choice of
appropriate exponent, i.e. you have to provide this in instantiation
time.

hth, and let me know about any progress,
Friedrich

P.S.: I just gave the thread link and didn't look into it further.
But it should be the message I remembered.

--
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] scientific notation in ticklabels for linear plot

2010-10-19 Thread David Pine
I agree with Jonathan and would very much like to see this feature implemented. 
 The example shown in the thread didn't show the × symbol, however, which 
would be nice to have -- e.g. it should read 2.0 × 10² rather than 2.0 10².

David


On Oct 19, 2010, at 1:08 PM, Friedrich Romstedt wrote:

 2010/10/18 Jonathan Slavin jsla...@cfa.harvard.edu:
 I'm wondering if there's some relatively automatic way to have the
 ticklabels to come out in scientific notation for an axis that uses a
 linear scale (and has a range that warrants scientific notation)?  For
 example, an axis that goes from 0 to 2.E18 by default uses the labels 0,
 0.5, 1.0, 1.5, 2.0 and puts 1e18 at the end of the axis.  To me this is
 unappealing. 1e18 is a computer programming way to write the 10^{18} (in
 LaTeX formatting).  In IDL the ticklabels are 5.0x10^{17}, 1.0x10^{18},
 1.5x10^{18}, 2.0x10^{18}.  This is one instance where I think IDL gets
 it right and matplotlib gets it wrong.  So, as far as I can tell, one
 can give the ticklabels by hand, and so I could achieve my desired
 labels that way, but it'd be nice to have a more automatic way to do it.
 Searching the examples, I've come up empty so far.  I would also
 advocate changing the default format for labeling axes that fall in this
 category.  Do the developers have any opinions on this?
 
 There's a thread some monthes ago about this, I provided code to do
 this.  Currently, this Formatter class didn't make it into matplotlib
 due a lack of providing a patch by me.  If others agree that this
 would be a good feature, I'll clean the code if necessary and provide
 another patch for this.
 
 Looking for the thread ...
 http://article.gmane.org/gmane.comp.python.matplotlib.general/23824/match=scientific+notation+friedrich
 
 IIRC, the formatter class does NOT provide automatic choice of
 appropriate exponent, i.e. you have to provide this in instantiation
 time.
 
 hth, and let me know about any progress,
 Friedrich
 
 P.S.: I just gave the thread link and didn't look into it further.
 But it should be the message I remembered.
 
 --
 Download new Adobe(R) Flash(R) Builder(TM) 4
 The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
 Flex(R) Builder(TM)) enable the development of rich applications that run
 across multiple browsers and platforms. Download your free trials today!
 http://p.sf.net/sfu/adobe-dev2dev
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] scientific notation in ticklabels for linear plot

2010-10-19 Thread Friedrich Romstedt
What about inserting \cdot, that's the scientific notation I do prefer?

If I'm not mistaken that's what I did that time, might be unreadable
in the preview?  I checked, when you look close you see the dot in
gmane preview.

We can make this customisable, with \times as an alternative option.

Friedrich

--
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] scientific notation in ticklabels for linear plot

2010-10-19 Thread David Pine
I like the times symbol but others prefer the dot (which I missed in the gmane 
preview!).  So I like your suggestion of providing an option to use either 
\cdot or \times.

David

On Oct 19, 2010, at 3:23 PM, Friedrich Romstedt wrote:

 What about inserting \cdot, that's the scientific notation I do prefer?
 
 If I'm not mistaken that's what I did that time, might be unreadable
 in the preview?  I checked, when you look close you see the dot in
 gmane preview.
 
 We can make this customisable, with \times as an alternative option.
 
 Friedrich


--
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] scientific notation in ticklabels for linear plot

2010-10-19 Thread Friedrich Romstedt
2010/10/19 David Pine djp...@gmail.com:
 I like the times symbol but others prefer the dot (which I missed in the 
 gmane preview!).  So I like your suggestion of providing an option to use 
 either \cdot or \times.

Okay, I'll try to look into it next week, is that okay with you both?
I don't want to do it now since there might be more under the hood,
just thinking about automatic exponent choice, I have a module for
that, but it needs to pick up all the range the formatter spans over.

I'd say we also have use for three other configs of the exponent choice:
a) largest
b) smallest
c) mean
d) dynamic
exponent.

Examples:
(a)  0.001 10^2 ... 2.0 10^2
(b)  1.0 10^-1 ... 200.0 10^-1
(c)  0.01 10^1 ... 20.0 10^1
(d)  1.0 10^-1 ... 2.0 10^2
Sorry if there's some mistake but you see the principle.

Also the number of digits present need to be configurable ... enough for a week.

I favour (c) as the default, and 2 digits precision.

Friedrich

--
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] scientific notation in ticklabels for linear plot

2010-10-19 Thread Jonathan Slavin
I think that'd be fine -- i.e. the option of \cdot or \times (though in
the gmane preview the dot looks a bit low).  In the mean time, I came up
with the method below that worked for my purpose.

Jon


import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import FuncFormatter

def scinot(x,pos=None):
if x == 0:
s = '0'
else:
xp = int(np.floor(np.log10(np.abs(x
mn = x/10.**xp
# Here we truncate to 2 significant digits -- may not be enough 
# in all cases
s = '$'+str('%.1f'%mn) +'\\times 10^{'+str(xp)+'}$'
return s

x = np.linspace(0.,2.,10)*1.E18
y = 2.*(x/1.E18) - 1.
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x,y)
ax.xaxis.set_major_formatter(FucFormatter(scinot))
plt.show()


On Tue, 2010-10-19 at 15:30 -0400, David Pine wrote:
 I like the times symbol but others prefer the dot (which I missed in the 
 gmane preview!).  So I like your suggestion of providing an option to use 
 either \cdot or \times.
 
 David
 
 On Oct 19, 2010, at 3:23 PM, Friedrich Romstedt wrote:
 
  What about inserting \cdot, that's the scientific notation I do prefer?
  
  If I'm not mistaken that's what I did that time, might be unreadable
  in the preview?  I checked, when you look close you see the dot in
  gmane preview.
  
  We can make this customisable, with \times as an alternative option.
  
  Friedrich
 
-- 
__
Jonathan D. Slavin  Harvard-Smithsonian CfA
jsla...@cfa.harvard.edu 60 Garden Street, MS 83
phone: (617) 496-7981   Cambridge, MA 02138-1516
 cell: (781) 363-0035   USA
__


--
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] scientific notation in ticklabels for linear plot

2010-10-19 Thread Friedrich Romstedt
2010/10/19 Jonathan Slavin jsla...@cfa.harvard.edu:
 I think that'd be fine -- i.e. the option of \cdot or \times (though in
 the gmane preview the dot looks a bit low).  In the mean time, I came up
 with the method below that worked for my purpose.

Okay thx

 import matplotlib.pyplot as plt
 import numpy as np
 from matplotlib.ticker import FuncFormatter

 def scinot(x,pos=None):
    if x == 0:
        s = '0'
    else:
        xp = int(np.floor(np.log10(np.abs(x
        mn = x/10.**xp
        # Here we truncate to 2 significant digits -- may not be enough
        # in all cases
        s = '$'+str('%.1f'%mn) +'\\times 10^{'+str(xp)+'}$'
    return s

 x = np.linspace(0.,2.,10)*1.E18
 y = 2.*(x/1.E18) - 1.
 fig = plt.figure()
 ax = fig.add_subplot(111)
 ax.plot(x,y)
 ax.xaxis.set_major_formatter(FucFormatter(scinot))

typo for the records although abvious:  FuncFormatter

 plt.show()

Okay I can do the tedious work of changing my code ASAP but with low
priority ...

Friedrich

--
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] scientific notation in ticklabels for linear plot

2010-10-19 Thread Jonathan Slavin
Friedrich,

Our e-mails crossed.  I don't think the numbers need to have the same
exponent.  I would go with (d) as my example does.  The more difficult
part to my mind is the number of significant digits to use.  The current
code that determines whether to use an offset or not must look at the
number of significant digits needed to represent the ticklabels.  To me
what would be optimal is to, by default, use scientific notation (when
the ticklabel numbers are larger or smaller than some range, say 10^3
and 10^-3) except when an offset is called for, say more than 3
significant digits are needed to represent the ticklabel numbers in
scientific notation.

Jon

On Tue, 2010-10-19 at 21:41 +0200, Friedrich Romstedt wrote:
 2010/10/19 David Pine djp...@gmail.com:
  I like the times symbol but others prefer the dot (which I missed in the 
  gmane preview!).  So I like your suggestion of providing an option to use 
  either \cdot or \times.
 
 Okay, I'll try to look into it next week, is that okay with you both?
 I don't want to do it now since there might be more under the hood,
 just thinking about automatic exponent choice, I have a module for
 that, but it needs to pick up all the range the formatter spans over.
 
 I'd say we also have use for three other configs of the exponent choice:
 a) largest
 b) smallest
 c) mean
 d) dynamic
 exponent.
 
 Examples:
 (a)  0.001 10^2 ... 2.0 10^2
 (b)  1.0 10^-1 ... 200.0 10^-1
 (c)  0.01 10^1 ... 20.0 10^1
 (d)  1.0 10^-1 ... 2.0 10^2
 Sorry if there's some mistake but you see the principle.
 
 Also the number of digits present need to be configurable ... enough for a 
 week.
 
 I favour (c) as the default, and 2 digits precision.
 
 Friedrich
-- 
__
Jonathan D. Slavin  Harvard-Smithsonian CfA
jsla...@cfa.harvard.edu 60 Garden Street, MS 83
phone: (617) 496-7981   Cambridge, MA 02138-1516
 cell: (781) 363-0035   USA
__


--
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] scientific notation in ticklabels for linear plot

2010-10-18 Thread Jonathan Slavin
Hi,

I'm wondering if there's some relatively automatic way to have the
ticklabels to come out in scientific notation for an axis that uses a
linear scale (and has a range that warrants scientific notation)?  For
example, an axis that goes from 0 to 2.E18 by default uses the labels 0,
0.5, 1.0, 1.5, 2.0 and puts 1e18 at the end of the axis.  To me this is
unappealing. 1e18 is a computer programming way to write the 10^{18} (in
LaTeX formatting).  In IDL the ticklabels are 5.0x10^{17}, 1.0x10^{18},
1.5x10^{18}, 2.0x10^{18}.  This is one instance where I think IDL gets
it right and matplotlib gets it wrong.  So, as far as I can tell, one
can give the ticklabels by hand, and so I could achieve my desired
labels that way, but it'd be nice to have a more automatic way to do it.
Searching the examples, I've come up empty so far.  I would also
advocate changing the default format for labeling axes that fall in this
category.  Do the developers have any opinions on this?

Regards,
Jon


--
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] scientific notation

2010-07-17 Thread Friedrich Romstedt
2010/7/15 Waléria Antunes David waleriantu...@gmail.com:
 But, i don't know how do...

 I tried, but don't, most failed

Maybe this is something in the direction you want?  You have to adapt
the test file.

Friedrich


embedded_sci_formatter.py
Description: Binary data
attachment: test.png

test.py
Description: Binary data
--
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] scientific notation

2010-07-16 Thread Waléria Antunes David
Hi...

I tried the first option, but failed see my image attached

And the second option, i don't understand the variable 'val'

...?

On Thu, Jul 15, 2010 at 3:22 PM, Ryan May rma...@gmail.com wrote:

 On Thu, Jul 15, 2010 at 8:41 AM, Waléria Antunes David
 waleriantu...@gmail.com wrote:
  Hi all,
 
  I have a code base so that:
 
 
  from pylab import *
  x = arange (3000,3400)
  y = -108 * (3.0e14 ** 2)/x**2
 
  pylab..title(Teste)
  pylab.savefig(imagem.png)
  plot(x, y)
 
 
  Well the values of the function range(3000,3400) are in Hz..i
 need
  to pass GHz which would be in scientific notation as follows bellow:
 
  3000 Hz = 3,0 × 10-6 GHz
  3400 Hz = 3,4 x 10-6 Ghz
 
  How do I make the graph x-axis is shown in figures
  scientific notation, for this currently so
 
  3000,3050,3100,,3400
 
  in scientific notation is: (3.0e-6,  3.4e-6)

 One way is to just change the values in the GHz and plot them:

 plot(x/1e9, y)
 # Need to change some limits so that they show up in scientific notation:
 gca().xaxis.get_major_formatter().set_powerlimits((-5,5))

 The other way is make a custom formatter that changes the values of the
 ticks:

 def fmt_ghz(val, pos=None):
return '%g' % (val / 1e9)

 plot(x, y)
 gca().xaxis.set_major_formatter(FuncFormatter(fmt_ghz))

 You can get more information here:
 http://matplotlib.sourceforge.net/api/ticker_api.html

 Ryan

 --
 Ryan May
 Graduate Research Assistant
 School of Meteorology
 University of Oklahoma

--
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] scientific notation

2010-07-16 Thread Waléria Antunes David
I forgot of the my image.

On Fri, Jul 16, 2010 at 9:10 AM, Waléria Antunes David 
waleriantu...@gmail.com wrote:

 Hi...

 I tried the first option, but failed see my image attached

 And the second option, i don't understand the variable 'val'

 ...?


 On Thu, Jul 15, 2010 at 3:22 PM, Ryan May rma...@gmail.com wrote:

 On Thu, Jul 15, 2010 at 8:41 AM, Waléria Antunes David
 waleriantu...@gmail.com wrote:
  Hi all,
 
  I have a code base so that:
 
 
  from pylab import *
  x = arange (3000,3400)
  y = -108 * (3.0e14 ** 2)/x**2
 
  pylab..title(Teste)
  pylab.savefig(imagem.png)
  plot(x, y)
 
 
  Well the values of the function range(3000,3400) are in Hz..i
 need
  to pass GHz which would be in scientific notation as follows bellow:
 
  3000 Hz = 3,0 × 10-6 GHz
  3400 Hz = 3,4 x 10-6 Ghz
 
  How do I make the graph x-axis is shown in figures
  scientific notation, for this currently so
 
  3000,3050,3100,,3400
 
  in scientific notation is: (3.0e-6,  3.4e-6)

 One way is to just change the values in the GHz and plot them:

 plot(x/1e9, y)
 # Need to change some limits so that they show up in scientific notation:
 gca().xaxis.get_major_formatter().set_powerlimits((-5,5))

 The other way is make a custom formatter that changes the values of the
 ticks:

 def fmt_ghz(val, pos=None):
return '%g' % (val / 1e9)

 plot(x, y)
 gca().xaxis.set_major_formatter(FuncFormatter(fmt_ghz))

 You can get more information here:
 http://matplotlib.sourceforge.net/api/ticker_api.html

 Ryan

 --
 Ryan May
 Graduate Research Assistant
 School of Meteorology
 University of Oklahoma



attachment: image.png--
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] scientific notation

2010-07-16 Thread Benjamin Root
Please attach the code you used to generate this image.

Ben Root

On Fri, Jul 16, 2010 at 7:11 AM, Waléria Antunes David 
waleriantu...@gmail.com wrote:

 I forgot of the my image.


 On Fri, Jul 16, 2010 at 9:10 AM, Waléria Antunes David 
 waleriantu...@gmail.com wrote:

 Hi...

 I tried the first option, but failed see my image attached

 And the second option, i don't understand the variable 'val'

 ...?


 On Thu, Jul 15, 2010 at 3:22 PM, Ryan May rma...@gmail.com wrote:

 On Thu, Jul 15, 2010 at 8:41 AM, Waléria Antunes David
 waleriantu...@gmail.com wrote:
  Hi all,
 
  I have a code base so that:
 
 
  from pylab import *
  x = arange (3000,3400)
  y = -108 * (3.0e14 ** 2)/x**2
 
  pylab..title(Teste)
  pylab.savefig(imagem.png)
  plot(x, y)
 
 
  Well the values of the function range(3000,3400) are in Hz..i
 need
  to pass GHz which would be in scientific notation as follows bellow:
 
  3000 Hz = 3,0 × 10-6 GHz
  3400 Hz = 3,4 x 10-6 Ghz
 
  How do I make the graph x-axis is shown in figures
  scientific notation, for this currently so
 
  3000,3050,3100,,3400
 
  in scientific notation is: (3.0e-6,  3.4e-6)

 One way is to just change the values in the GHz and plot them:

 plot(x/1e9, y)
 # Need to change some limits so that they show up in scientific notation:
 gca().xaxis.get_major_formatter().set_powerlimits((-5,5))

 The other way is make a custom formatter that changes the values of the
 ticks:

 def fmt_ghz(val, pos=None):
return '%g' % (val / 1e9)

 plot(x, y)
 gca().xaxis.set_major_formatter(FuncFormatter(fmt_ghz))

 You can get more information here:
 http://matplotlib.sourceforge.net/api/ticker_api.html

 Ryan

 --
 Ryan May
 Graduate Research Assistant
 School of Meteorology
 University of Oklahoma





 --
 This SF.net email is sponsored by Sprint
 What will you do first with EVO, the first 4G phone?
 Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] scientific notation

2010-07-15 Thread Waléria Antunes David
Hi all,

I have a code base so that:


from pylab import *
x = arange (3000,3400)
y = -108 * (3.0e14 ** 2)/x**2

pylab..title(Teste)
pylab.savefig(imagem.png)
plot(x, y)


Well the values of the function range(3000,3400) are in Hz..i need
to pass GHz which would be in scientific notation as follows bellow:

3000 Hz = 3,0 × 10-6 GHz
3400 Hz = 3,4 x 10-6 Ghz

How do I make the graph x-axis is shown in figures
scientific notation, for this currently so

3000,3050,3100,,3400

in scientific notation is: (3.0e-6,  3.4e-6)

Can someone help me?

See my attachment

I need to show this values in scientific notation..

Waléria
attachment: current_image.jpg--
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] scientific notation

2010-07-15 Thread Benjamin Root
On Thu, Jul 15, 2010 at 8:41 AM, Waléria Antunes David 
waleriantu...@gmail.com wrote:

 Hi all,

 I have a code base so that:


 from pylab import *
 x = arange (3000,3400)
 y = -108 * (3.0e14 ** 2)/x**2

 pylab..title(Teste)
 pylab.savefig(imagem.png)
 plot(x, y)


 Well the values of the function range(3000,3400) are in Hz..i need
 to pass GHz which would be in scientific notation as follows bellow:

 3000 Hz = 3,0 × 10-6 GHz
 3400 Hz = 3,4 x 10-6 Ghz

 How do I make the graph x-axis is shown in figures
 scientific notation, for this currently so

 3000,3050,3100,,3400

 in scientific notation is: (3.0e-6,  3.4e-6)

 Can someone help me?

 See my attachment

 I need to show this values in scientific notation..

 Waléria



Waleria,

I believe you are looking to use the ticker API.  Particularly the
FormatStrFormatter that accepts a sprintf()-like format string to express
your tick values.  For your particular example, --off the top of my head--
the string format would be %.1e.

http://matplotlib.sourceforge.net/api/ticker_api.html

I hope this helps.

Ben Root
--
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] scientific notation

2010-07-15 Thread Waléria Antunes David
But, i don't know how do...

I tried, but don't, most failed

On Thu, Jul 15, 2010 at 11:25 AM, Benjamin Root ben.r...@ou.edu wrote:


 On Thu, Jul 15, 2010 at 8:41 AM, Waléria Antunes David 
 waleriantu...@gmail.com wrote:

 Hi all,

 I have a code base so that:


 from pylab import *
 x = arange (3000,3400)
 y = -108 * (3.0e14 ** 2)/x**2

 pylab..title(Teste)
 pylab.savefig(imagem.png)
 plot(x, y)


 Well the values of the function range(3000,3400) are in Hz..i need
 to pass GHz which would be in scientific notation as follows bellow:

 3000 Hz = 3,0 × 10-6 GHz
 3400 Hz = 3,4 x 10-6 Ghz

 How do I make the graph x-axis is shown in figures
 scientific notation, for this currently so

 3000,3050,3100,,3400

 in scientific notation is: (3.0e-6,  3.4e-6)

 Can someone help me?

 See my attachment

 I need to show this values in scientific notation..

 Waléria



 Waleria,

 I believe you are looking to use the ticker API.  Particularly the
 FormatStrFormatter that accepts a sprintf()-like format string to express
 your tick values.  For your particular example, --off the top of my head--
 the string format would be %.1e.

 http://matplotlib.sourceforge.net/api/ticker_api.html

 I hope this helps.

 Ben Root

--
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] scientific notation

2010-07-15 Thread Ryan May
On Thu, Jul 15, 2010 at 8:41 AM, Waléria Antunes David
waleriantu...@gmail.com wrote:
 Hi all,

 I have a code base so that:


 from pylab import *
 x = arange (3000,3400)
 y = -108 * (3.0e14 ** 2)/x**2

 pylab..title(Teste)
 pylab.savefig(imagem.png)
 plot(x, y)


 Well the values of the function range(3000,3400) are in Hz..i need
 to pass GHz which would be in scientific notation as follows bellow:

 3000 Hz = 3,0 × 10-6 GHz
 3400 Hz = 3,4 x 10-6 Ghz

 How do I make the graph x-axis is shown in figures
 scientific notation, for this currently so

 3000,3050,3100,,3400

 in scientific notation is: (3.0e-6,  3.4e-6)

One way is to just change the values in the GHz and plot them:

plot(x/1e9, y)
# Need to change some limits so that they show up in scientific notation:
gca().xaxis.get_major_formatter().set_powerlimits((-5,5))

The other way is make a custom formatter that changes the values of the ticks:

def fmt_ghz(val, pos=None):
return '%g' % (val / 1e9)

plot(x, y)
gca().xaxis.set_major_formatter(FuncFormatter(fmt_ghz))

You can get more information here:
http://matplotlib.sourceforge.net/api/ticker_api.html

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

--
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] scientific notation \times symbol

2009-12-07 Thread Hao Wen
Hi there:

I tried to plot large numbers and scientific notation has to be used.
But instead of \times symbol, it used e, which cannot be accepted as
publishable. Anyone know how to deal with that?

My original code is:

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import ScalarFormatter

# data generation
x = np.arange(1,1e3,20)
y = x**2

formatter = ScalarFormatter()
formatter.set_scientific(True)
formatter.set_powerlimits((-3,3))

fig = plt.figure()
ax = fig.add_subplot(111)
ax.xaxis.set_major_formatter(formatter)
ax.yaxis.set_major_formatter(formatter)
ax.plot(x,y)

plt.show()




--
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users