title: Cleanest way to hide every nth tick label in matplotlib colorbar?
body: <p>The labels on my horizontal colorbar are too close together and I don't want to reduce text size further:</p>
  
  <pre><code>cbar = plt.colorbar(shrink=0.8, orientation='horizontal', extend='both', pad=0.02)
  cbar.ax.tick_params(labelsize=8)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/t52fd.png" alt="horizontal colorbar with bad labels"></p>
  
  <p>I'd like to preserve all ticks, but remove every other label.  </p>
  
  <p>Most examples I've found pass a user-specified list of strings to cbar.set_ticklabels().  I'm looking for a general solution.  </p>
  
  <p>I played around with variations of</p>
  
  <pre><code>cbar.set_ticklabels(cbar.get_ticklabels()[::2])
  </code></pre>
  
  <p>and</p>
  
  <pre><code>cbar.ax.xaxis.set_major_locator(matplotlib.ticker.MaxNLocator(nbins=4))
  </code></pre>
  
  <p>but I haven't found the magic combination.  </p>
  
  <p>I know there must be a clean way to do this using a locator object.  </p>