打开“log”刻度时,x轴上的数字消失。
import numpy as np
import matplotlib.pyplot as plt
plt.plot( range(1,10) , range(1,10) , color='#aaaaff')
plt.xscale('log')
plt.xticks(range(1,10) )
plt.show()
如果我注释掉xscale
,则会打印x轴上的数字。有人可以阐明为什么这在log
比例轴上不起作用以及如何实现这一点?
编辑:
简化代码,以便无需数据文件即可使用。同样的事情:没有数字!!
答案 0 :(得分:2)
默认情况下,日志轴的刻度位置位于基数10.因此,在上述情况下,唯一可能的xtick
位于1。
如果您将xticks
更改为
plt.xticks([1,10])
您可以在1
和10
找到答案。
你也可以玩ticker
,这可以让你做很多事情。如,
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import LogLocator
fig = plt.figure(1, [5,4])
ax = fig.add_subplot(111)
ax.plot( range(1,100) , range(1,100) , color='#aaaaff')
ax.set_xscale('log')
# This is default, so play with it
ax.xaxis.set_major_locator(LogLocator(base = 10.0))
plt.show()
如果您使用:
ax.xaxis.set_major_locator(LogLocator(base = 100.0))
然后你得到