title: Ticks and Labels at different positions in axis
body: <p>I'm trying to make a figure in which I'd like to have labels and also ticks in the x-axis but at different positions. However, it seems that after setting the first ticks, when trying to define new ticks the previous ones are "forgotten". For example:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  
  xs = [1, 4, 7, 11, 14, 17, 20, 23, 26, 29]
  ys = [2.0, 1.667, 2.0, 0.333, 1.0, 0.667, 1.667, 1.0, 1.0, 1.0]
  
  # where we want our labels
  ticks1 = [5.0, 15.0, 25.0]
  labs = ['A', 'B', 'C']
  
  fig, ax = plt.subplots()
  ax.plot(xs, ys)
  
  # I think I have to define ticks here to position the labels...
  ax.set_xticks(ticks1)
  ax.set_xticklabels(labs)
  
  ax.tick_params(axis='x', length=0)
  
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/TQGgQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TQGgQ.png" alt="enter image description here"></a></p>
  
  <p>So far is good, with the wanted arrangement. <code>ABC</code> are used to mark different groups of data points, and they are more or less in the middle of each respective group (I'll add vertical lines afterwards to make this separation more obvious), but ticks should reflect the data, not these artificial labels.</p>
  
  <p>But if I try to now add a different set of ticks to the same axis, the labels plotted above migrate to the new ticks and do not keep their old position:</p>
  
  <pre><code># ...but want to have ticks for this range
  ticks2 = [x for x in range(0, 33, 3)]
  ax.set_xticks(ticks2)
  ax.tick_params(axis='x', length=5)
  
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/1hSov.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1hSov.png" alt="enter image description here"></a></p>
  
  <p>What is the correct way to achieve the desired output in <code>matplotlib</code>?</p>