Cleanest way to hide every nth tick label in matplotlib colorbar?

前端 未结 4 1980
[愿得一人]
[愿得一人] 2020-11-27 04:08

The labels on my horizontal colorbar are too close together and I don\'t want to reduce text size further:

cbar = plt.colorbar(shrink=0.8, orientation=\'hori         


        
4条回答
  •  伪装坚强ぢ
    2020-11-27 04:32

    One-liner for those who are into that!

    n = 7  # Keeps every 7th label
    [l.set_visible(False) for (i,l) in enumerate(ax.xaxis.get_ticklabels()) if i % n != 0]
    

提交回复
热议问题