title: How can I offset the x-axis ticks so every other is slightly lower/higher?
body: <p>The minor x-axis labels on my plot are very dense. Instead of making them smaller, I want to move every other one slightly down so they fit within the axis. Something like <a href="https://stackoverflow.com/a/53119793/8315879">this</a>. I tried <a href="https://stackoverflow.com/questions/6406368/matplotlib-move-x-axis-label-downwards-but-not-x-axis-ticks">label padding</a> but no success. </p>
  
  <p><a href="https://i.stack.imgur.com/w4mz0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w4mz0.png" alt="enter image description here"></a></p>
  
  <p>Code:</p>
  
  <pre class="lang-py prettyprint-override"><code>fig, ax1 = plt.subplots(figsize=(18, 6))
  
  ax1.plot(data['date_time'], data.Casual, color='g')
  ax1.plot(data['date_time'], data.Registered, color='b')
  
  ax1.set(xlabel='', ylabel='Total # of trips started')
  ax1.yaxis.label.set_size(13)
  ax1.xaxis.set(
      major_locator=mdates.DayLocator(),
      major_formatter=mdates.DateFormatter('\n\n%A'),
      minor_locator=mdates.HourLocator(byhour=range(0,24,1)),
      minor_formatter=mdates.DateFormatter('%-H'),
  )
  ax1.tick_params(axis='x', which='minor', bottom=True)
  ax1.set_xbound(data['date_time'][0],data['date_time'][166])
  ax1.yaxis.set_ticks(np.arange(0, 550, 50))
  ax1.set_ybound(0,550)
  ax1.yaxis.grid(True, which='major')
  ax1.xaxis.grid(True, which='major', color='green')
  
  #borders
  ax1.spines['left'].set_color('0.0')
  ax1.spines['right'].set_color('0.0')
  ax1.spines['bottom'].set_color('0.0')
  
  # Create offset transform by 74 points in x direction
  dx = 74/72.; dy = 0/72. 
  offset = mpl.transforms.ScaledTranslation(dx, dy, fig.dpi_scale_trans)
  
  # apply offset transform to all x ticklabels.
  for label in ax1.xaxis.get_majorticklabels():
      label.set_transform(label.get_transform() + offset)
  
  ### Trying to move them up and down here ###
  labels_formatted = [label if i%2==0 else label+'\n' for i, label in enumerate(ax1.xaxis.get_majorticklabels())]
  ax1.set_xticklabels(labels_formatted)
  
  
  plt.show()
  </code></pre>