Python hide ticks but show tick labels

前端 未结 9 822
Happy的楠姐
Happy的楠姐 2020-12-07 11:23

I can remove the ticks with

ax.set_xticks([]) 
ax.set_yticks([]) 

but this removes the labels as well. Any way I can plot the tick labels b

9条回答
  •  情书的邮戳
    2020-12-07 11:57

    matplotlib.pyplot.setp(*args, **kwargs) is used to set properties of an artist object. You can use this in addition to get_xticklabes() to make it invisible.

    something on the lines of the following

    import matplotlib.pyplot as plt
    fig = plt.figure()
    ax = fig.add_subplot(2,1,1)
    ax.set_xlabel("X-Label",fontsize=10,color='red')
    plt.setp(ax.get_xticklabels(),visible=False)
    

    Below is the reference page http://matplotlib.org/api/pyplot_api.html

提交回复
热议问题