title: Matplotlib: add custom tick label and remove custom tick on y-axis
body: <p>I would like to remove a tick and its label and instead add a new tick label in a different (but close) location without the tick itself. I am not sure how to do this. An example is given.</p>
  
  <pre><code>import matplotlib.pyplot as plt
  def main():
      fig = plt.figure()
      x = [1,2,3,4,5]
      y = x
      ax = fig.add_subplot(1,1,1)
      y_ticks = ax.yaxis.get_major_ticks()
      y_ticks[-1].label.set_visible(False)
      ax.set_yticks([3.7], minor=True)
      ax.set_yticklabels(["100"], minor=True)
      ax.plot(x,y)
      plt.show()
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>What is left for me here is to remove the ticks located at y=3.5, 3.7.</p>
  
  <p>Also, as you can see I accessed y_ticks[-1] to set its label to be invisible. This was chosen arbitrarily and actually I would appreciate it if someone could explain why y_ticks[-1] chooses the tick located at y=3.5.</p>
  
  <p>Thanks</p>
  
  <p><a href="https://i.stack.imgur.com/11IY4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/11IY4.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Edit:</strong></p>
  
  <p>As was mentioned in the two answers I changed my code to:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  
  def main():
      fig = plt.figure()
      x = [1,2,3,4,5]
      y = x
      ax = fig.add_subplot(1,1,1)
      ax.plot(x,y)
      ax.set_yticks([3.7], minor=True)
      ax.set_yticklabels(["100"], minor=True)
      y_ticks = ax.yaxis.get_major_ticks()
      y_ticks[5].set_visible(False)
      y_ticks[6].label.set_visible(False)
      plt.show()
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>This yields the plot below and you can see that <code>y_ticks[5]</code> refers to the tick located at <code>y=3.5</code> and <code>y_ticks[6]</code> to the tick located at <code>y=4.0</code> - it skips the tick located at <code>y=3.7</code>. So how can I access it and remove ONLY the tick?
  The two suggestions only explain how to remove either both tick and label or only the label (without the tick) and I am looking for removing the tick and keeping the label.</p>
  
  <p><a href="https://i.stack.imgur.com/UvR5y.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UvR5y.jpg" alt="enter image description here"></a></p>