2014-12-02 148 views
1

當我適用:控制刻度標記的間隔

ax.set_yscale('log') 

在matplotlib一個軸,它創建用於10.有時每多個蜱,這可以蜂得多,例如見下面的截圖:

                enter image description here

相反,我想有一個剔,說的100每多,或1000每一個倍數,同時保留對數標度。

我該怎麼做matplotlib?

回答

3

只需使用matplotlib.ticker.LogLocator

import numpy as np 
import matplotlib.pyplot as plt 
from matplotlib.ticker import LogLocator 
x = np.linspace(0, 10, 10) 
y = 2**x 
f = plt.figure() 
ax = f.add_subplot(111) 
plt.yscale('log') 
ax.yaxis.set_major_locator(LogLocator(base=100)) 
ax.plot(x, y) 
plt.show() 

enter image description here 如果你希望做同樣的未成年人定位,或調整它,你喜歡的任何其他方式。