2012-05-31 35 views
14

que tienen algo de código:¿Cómo establecer "paso" en el eje X en mi figura en matplotlib python 2.6.6?

#!/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() 

y me da esa cifra: my figure

Como se puede ver, el "paso" en el eje X es de 0,5, pero me gustaría que lo ponen a 1. ¿Como hacerlo?

Cuando uso plt.xticks(1) me da errores:

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()

que utilizo Python 2.6.6 en Ubuntu 10.10 ....

Respuesta

23
plt.xticks([1, 2, 3, 4, 5]) 

xticks documentation.

Five x-ticks.

+1

Wow , gracias, funciona perfectamente :) No sé cómo podría extrañar esto;) Gracias agai ¡norte! – mazix

+0

@mazix: si esta respuesta resolvió su problema, debe sentirse libre de aceptarlo (http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) – mgilson

+0

@mgilson: thanku Tanto, acabo de aceptar la respuesta de Steve :) – mazix

Cuestiones relacionadas