2011-07-07 5 views
2

J'ai écrit un simple programme en Python en utilisant Matplotlib pour dessiner des lignes dans un système de coordonnées. Je veux Description X-axe à "2006, 2007, 2008", mais est plutôt montre que "0, 0,5, 1, 1,5, 2,0 + 2.006e3" CodeAxe X dans Matplotlib

est ici:

import matplotlib.pyplot 

import numpy as np 

fig = matplotlib.pyplot.figure() 

a=[2006,2007,2008] 

b=[-1,3,5] 

matplotlib.pyplot.plot(a, b, 'go-', label='line 1', linewidth=2) 

matplotlib.pyplot.axis([2006, 2008, -1, 5]) 

matplotlib.pyplot.show() 
+0

Cela ressemble à votre axe des x pourrait être des dates. Si c'est le cas, vous pouvez regarder dans 'plot_date()' et ses cousins. – matt

Répondre

1

Au lieu de

plt.axis([2006, 2008, -1, 5]) 

utilisation plt.xticks:

plt.xticks(a, map(str,a)) 

PS: Son pratique pour importer matplotlib.pyplot avec

import matplotlib.pyplot as plt 

car cela réduit le frappe.