Python hide ticks but show tick labels

前端 未结 9 804
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:32

    This Worked out pretty well for me! try it out

    import matplotlib.pyplot as plt
    import numpy as np
    
    plt.figure()
    
    languages =['Python', 'SQL', 'Java', 'C++', 'JavaScript']
    pos = np.arange(len(languages))
    popularity = [56, 39, 34, 34, 29]
    
    plt.bar(pos, popularity, align='center')
    plt.xticks(pos, languages)
    plt.ylabel('% Popularity')
    plt.title('Top 5 Languages for Math & Data \nby % popularity on Stack Overflow', 
    alpha=0.8)
    
    # remove all the ticks (both axes), 
    plt.tick_params(top='off', bottom='off', left='off', right='off', labelleft='off', 
    labelbottom='on')
    plt.show()
    

提交回复
热议问题