Ask Your Question
1

How can I avoit the scientific notation on the y-axis?

asked 2019-02-05 11:26:50 -0500

chrt gravatar image

Example: plot(exp(0.017*x), (x,0,2000))

edit retag flag offensive close merge delete

4 answers

Sort by » oldest newest most voted
1

answered 2019-02-05 23:02:42 -0500

updated 2019-02-05 23:03:43 -0500

You can use the matplotlib function FormatStrFormatter. This uses old-style Python formatting. The first argument is for the x-axis, the second for the y-axis. Using None gives the default setting.

sage: P = plot(exp(0.017*x), (x,0,2000))
sage: from matplotlib.ticker import FormatStrFormatter
sage: P.SHOW_OPTIONS['tick_formatter']=(None, FormatStrFormatter('%d'))
sage: P

I think it looks pretty horrible this way, and I would stick with scientific notation, as Emmanuel Charpentier said.

edit flag offensive delete link more

Comments

1

Or you can use matplotlib.ticker.StrMethodFormatter and new-style formatting: P.SHOW_OPTIONS['tick_formatter']=(None, StrMethodFormatter('{x:.2f}')).

John Palmieri gravatar imageJohn Palmieri ( 2019-02-05 23:13:12 -0500 )edit

Thank you John, that helped. I am just at the very beginning learning Sage/Phyton, so it will take some time to find a 'good' formatting. The Idea is to show the growth of the worlds population in a readable plot

chrt gravatar imagechrt ( 2019-02-06 03:40:49 -0500 )edit

That said, the scientific notation often is not really readable. Just get "e19 e19 e19 e19" or something. I wanted to try to fix this in a clunky way years ago but never quite got around to it; still unfortunate.

kcrisman gravatar imagekcrisman ( 2019-02-08 21:57:35 -0500 )edit

For this particular graph, the axis has labels '1e14', '2e14', '3e14', etc.

John Palmieri gravatar imageJohn Palmieri ( 2019-02-12 09:40:11 -0500 )edit
1

answered 2019-02-06 04:41:44 -0500

Sébastien gravatar image

An alternative is to use the log scale on the y-axis:

sage: plot(exp(0.017*x), (x,0,2000), scale="semilogy")

image description

Note that you may change the base of the logarithm this way:

sage: plot(exp(0.017*x), (x,0,2000), scale=("semilogy",3))

image description

See documentation of plot? for more information.

edit flag offensive delete link more

Comments

I want to show the dramatic of the growth of population. With the log-scaling, this is not visible for most eyes. So I found

sage: P = plot(exp(0.0178x)1.9833/10^15, (x,0,2100)) ....: from matplotlib.ticker import FormatStrFormatter ....: P.SHOW_OPTIONS['tick_formatter']=(None, FormatStrFormatter('%d' " Mrd.")) ....: P,

which does a good 'job'. (Sorry, I don't know how to set a graphik into a comment)

chrt gravatar imagechrt ( 2019-02-08 01:53:33 -0500 )edit
0

answered 2019-02-05 16:58:51 -0500

chrt gravatar image

Thanks for the response. Unfortunately, within the plotcommand, plot(exp(0.017*x),(x,0,2000)).n() I get the following message AttributeError: 'Graphics' object has no attribute 'n'

edit flag offensive delete link more
0

answered 2019-02-05 16:15:48 -0500

Emmanuel Charpentier gravatar image

Well...

sage: e^(2000*0.017).n()
5.83461742527455e14

Do yoy really need 14-digits wide y-axis markers ?

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-02-05 11:26:50 -0500

Seen: 76 times

Last updated: Feb 06