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

前端 未结 4 1975
[愿得一人]
[愿得一人] 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:18

    I use the following to show every 7th x label:

    plt.scatter(x, y)
    ax = plt.gca()
    temp = ax.xaxis.get_ticklabels()
    temp = list(set(temp) - set(temp[::7]))
    for label in temp:
        label.set_visible(False)
    plt.show()

    It's pretty flexible, as you can do whatever you want instead of plt.scatter. Hope it helps.

提交回复
热议问题