title: How can I change datetime format of x-axis values in matplotlib using python?
body: <p>How can I make this plot's x-axis looks better? </p>
  
  <p>Is there any way to show only 3 values in x-axis while plotting all values in my dataframe?</p>
  
  <p><a href="https://i.stack.imgur.com/Zxy7W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zxy7W.png" alt="image"></a></p>
  
  <p>I tried using <code>plt.xticks(rotation=70)</code> but it still cuts my numbers..</p>
  
  <p>As you can see, it shows the date in the format <code>MMM DD YYYY</code>.</p>
  
  <blockquote>
    <p>I wanna something like <code>MMM DD</code> or <code>DD MMM</code>. Or even writing in 2
    lines <code>DD MM \n YYYY</code>.</p>
    
    <p>How can I achieve that?</p>
  </blockquote>
  
  <p>This is the code used for generating the chart:</p>
  
  <pre><code>plt.plot(df_21d["Timestamp"], df_21d["Close"], label="Price", color="b")    
  
  plt.title("BTC - 21 Dias")
  
  plt.xlabel("Data")
  plt.ylabel("Preco (em USD)")
  
  plt.grid(True)
  
  plt.show()
  </code></pre>
  
  <p><strong>Here's my data:</strong></p>
  
  <p><em>df_21d["Timestamp"]</em></p>
  
  <pre><code>667   2016-05-27 08:00:00
  668   2016-05-27 08:30:00
  669   2016-05-27 09:00:00
  670   2016-05-27 09:30:00
  671   2016-05-27 10:00:00
  Name: Timestamp, dtype: datetime64[ns]
  </code></pre>
  
  <p><em>df_21d["Close"]</em></p>
  
  <pre><code>667    480.00
  668    471.36
  669    477.35
  670    476.55
  671    479.92
  Name: Close, dtype: float64
  </code></pre>
  
  <p>I dont know if I have to format <code>df_21d.Timestamp</code> or if it's a matplotlib configuration. Maybe formatting the timestamp and passing it as a vector using <code>plt.xticks()</code>... but I'm not sure about how do that...</p>
  
  <p>Or maybe even inserting only the first, the last and the middle value for the x-axis, with something like:</p>
  
  <pre><code>plt.xaxis_labels = (df_21d["Timestamp"][1], 
               df_21d["Timestamp"][len(df_21d["Timestamp"])/2], 
               df_21d["Timestamp"][len(df_21d["Timestamp"])])
  </code></pre>