简体   繁体   中英

How to avoid scientific notation in log-log plot after customising the font in Python

I use font_manager to customise the font of tick label. However, the tick label is displayed with scientific notation, eg 1e-10 in y-axis shown in the attached figure. How to avoid this scientific notation after customising the font and visualise it naturally as it shows in x-axis?

在此处输入图片说明

The code for this plot is

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
plt.loglog(10**-10, 10**-10)

from matplotlib import font_manager as fm
from matplotlib import rcParams
prop = fm.FontProperties(fname=rcParams["datapath"] + "/fonts/ttf/Helvetica.ttf")
ax.set_yticklabels(ax.get_yticks(), fontProperties=prop)

Unfortunately, there is no good API for setting the font properties to axis labels. One might expect there to be an option inside ax.tick_params - however that is not the case currently.

Options you have:

plt.setp(ax.get_yticklabels(), fontProperties=prop)

or

for l in ax.get_yticklabels():
    l.set_fontproperties(prop)

Example:

import matplotlib.pyplot as plt
from matplotlib import font_manager as fm

fig, ax = plt.subplots()
ax.loglog(10**-10, 10**-10)


prop = fm.FontProperties("Arial")
plt.setp(ax.get_yticklabels(), fontProperties=prop)

plt.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM