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

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

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

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

add a comment

1

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.

1

Or you can use `matplotlib.ticker.StrMethodFormatter`

and new-style formatting: `P.SHOW_OPTIONS['tick_formatter']=(None, StrMethodFormatter('{x:.2f}'))`

.

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

1

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

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

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

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

See documentation of `plot?`

for more information.

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.0178*x)*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)

0

Well...

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

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

0

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

Asked: ** 2019-02-05 18:26:50 +0200 **

Seen: **595 times**

Last updated: **Feb 06 '19**

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.