The standard form of matplotlib is to change e to \ times 10

In matplotlib, axes are sometimes displayed in standard form. The numbers are shown with check marks, and something like "1e-7" appears around the axis. Is there any way to change this to the written out $ \ times 10 ^ {- 7} $?

I do not want to change the labels on each individual tick. I want to change the text that appears once at the bottom of the axis, saying "1e-7".

+3
source share
2 answers

The simplest answer: use latex mode:

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True

x = np.arange(10000, 10011)
plt.plot(x)
plt.show()

Result:

enter image description here

EDIT

In fact, you do not need to use latex. ScalarFormatter, which is used by default, has the ability to use scientific notation:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker

x = np.arange(10000, 10011)
fig, ax = plt.subplots(1)
ax.plot(x)
formatter = mticker.ScalarFormatter(useMathText=True)
ax.yaxis.set_major_formatter(formatter)
plt.show()

Result:

enter image description here

+3
source
-1

All Articles