我有一些代碼:如何在matplotlib python 2.6.6中的圖中在軸X上設置「step」?
#!/usr/bin/env python
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
x = [1,2,3,4,5]
y = [1.2,1.9,3.1,4.2,4.8]
plt.plot(x,y)
plt.xlabel('OX')
plt.ylabel('OY')
plt.savefig('figure1.png')
plt.close()
,這讓我這個數字:my figure
,你可以看到,在X軸的「臺階」爲0.5,但我想將其設置爲1。如何做到這一點?
當我使用plt.xticks(1)
它給我的錯誤:
Traceback (most recent call last): File "overflow.py", line 13, in plt.xticks(1) File "/usr/lib/pymodules/python2.6/matplotlib/pyplot.py", line 998, in xticks locs = ax.set_xticks(args[0]) File "/usr/lib/pymodules/python2.6/matplotlib/axes.py", line 2064, in set_xticks return self.xaxis.set_ticks(ticks, minor=minor) File "/usr/lib/pymodules/python2.6/matplotlib/axis.py", line 1150, in set_ticks if len(ticks) > 1: TypeError: object of type 'int' has no len()
我使用Python 2.6.6在Ubuntu 10.10 ....
哇,謝謝,它完美的作品:)我不知道我怎麼會錯過這個;)謝謝你N! – mazix
@mazix:如果這個答案解決了你的問題,你應該隨時接受它(http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) – mgilson
@mgilson:thanku你這麼多,我剛剛接受了Steve的回答:) – mazix