set xticks label frequency with python
<p>I want to reduce the frequency of x tick marks. The x values are date :</p>

<pre><code>date=['20120101','20120101','20120101',...'20121231']
</code></pre>

<p>I have 24 time steps for each day of the year. And I would like to label the xticks each 24 time steps (i.e., each day). </p>

<p>Here is the code that I use:</p>

<pre><code>date=[]
val=[]
for lig in file(liste.txt):
   ligne=lig.split('')
   date.append(ligne[0])
   val.append(ligne[1])

plt.plot(date,val)
plt.setp(plt.gca().xaxis.get_majorticklabels(),rotation=90)
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%y%m%d'))
plt.gca().xaxis.set_major_locator(mdates.DayLocator(interval=4))
plt.show()
</code></pre>

<p>And here is my plot, there are no xticks label !</p>

<p><a href="http://i.stack.imgur.com/XmF1K.png" rel="nofollow"><img src="http://i.stack.imgur.com/XmF1K.png" alt="enter image description here"></a></p>

<p>Since there is no <em>complete</em> and working example, we have to guess: Is your <code>date</code> properly recognized as datetime object? If not, the <code>set_major_locator</code> in the date-format would result in no x-ticks.</p>

<p>You can achieve this using something like <code>date = datetime.datetime.strptime(date, '%Y%m%d')</code>.</p>

python matplotlib