Matplotlib 对数刻度格式
Matplotlib log scale formatting
使用 matplotlib
时,当为轴指定对数刻度时,标记该轴的默认方法是使用 10 的幂的数字,例如。 10^6。有没有一种简单的方法可以将所有这些标签更改为例如:1、5、10、20?
发现于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.])
使用 matplotlib
时,当为轴指定对数刻度时,标记该轴的默认方法是使用 10 的幂的数字,例如。 10^6。有没有一种简单的方法可以将所有这些标签更改为例如:1、5、10、20?
发现于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.])