2017-02-26 38 views
1

蜱我繪製matplotlib圖表,它看起來像this,其中x軸刻度顯示正確:冗餘壞日誌中matplotlib

這裏是我的代碼:

import matplotlib 
import matplotlib.pyplot as plt 
fig1, ax1 = plt.subplots() 
ax1.plot([1, 2, 3], [1,2,3]) 
ax1.set_xscale('log') 
plt.xlim(1,100) 
ax1.set_xticks([1,2,3,4,5,6,7,8,9,10]) 
ax1.get_xaxis().set_major_formatter(matplotlib.ticker.ScalarFormatter()) 
plt.show() 

然後我調整x軸的極限, plt.xlim(1,10) 下面是新的代碼:

import matplotlib 
import matplotlib.pyplot as plt 
fig1, ax1 = plt.subplots() 
ax1.plot([1, 2, 3], [1,2,3]) 
ax1.set_xscale('log') 
plt.xlim(1,10) 
ax1.set_xticks([1,2,3,4,5,6,7,8,9,10]) 
ax1.get_xaxis().set_major_formatter(matplotlib.ticker.ScalarFormatter()) 
plt.show() 

而且現在還有一些我並不需要一些錯誤的號碼:

我如何可達到第一個圖形爲小x軸的限制?

回答

0

當我更新到matplotlib 2+時,我遇到了同樣的問題。我在this thread找到了解決方案。問題似乎是次要的蜱蟲,您可以使用以下命令將其刪除:

plt.gca().xaxis.set_minor_formatter(matplotlib.ticker.NullFormatter())