简体   繁体   中英

Matplotlib log scale formatting

With matplotlib when a log scale is specified for an axis, the default method of labeling that axis is with numbers that are 10 to a power eg. 10^6. Is there an easy way to change all of these labels to for example: 1, 5, 10, 20?

Found in this thread

import matplotlib.pyplot as pl
from matplotlib.ticker import ScalarFormatter

fig = pl.figure()
ax = fig.add_subplot(111)

ax.set_xscale('log')
ax.set_xticks([1,2,5,10])
ax.get_xaxis().set_major_formatter(ScalarFormatter())
ax.set_xlim([1., 10.])

在此处输入图片说明

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