我正在学习 matplotlib 中的定位器。我自己写了一些代码来观察他们的具体结果。但是 IndexLocator 出现错误。
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.ticker as mtick
plt.switch_backend('Agg')
ax=plt.subplot(2,2,1)
ax.set_xlim(-5,47)
ax.xaxis.set_major_locator(mtick.IndexLocator(6,1))
print(ax.get_xticks())
上述代码异常。python 文件中出现最大允许大小超出错误。
有人可以给我一些建议吗?谢谢。
谢谢阿斯穆斯。当我添加情节语句时,错误消失了。但结果并不如预期。
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.ticker as mtick
plt.switch_backend('Agg')
ax=plt.subplot(2,2,1)
ax.set_xlim(-5,47)
ax.xaxis.set_major_locator(mtick.IndexLocator(6,1))
plt.plot([1,2,3,4]) #newly added
print(ax.get_xticks())
打印的是 [1]。但我认为正确的输出应该是 [1. 7. 13. 19. 25. 31. 37.]