Modify tick label text

前端 未结 10 1312
遥遥无期
遥遥无期 2020-11-22 07:13

I want to make some modifications to a few selected tick labels in a plot.

For example, if I do:

label = axes.yaxis.get_major_ticks()[2].label
label         


        
相关标签:
10条回答
  • Try this :

      fig,axis = plt.subplots(nrows=1,ncols=1,figsize=(13,6),sharex=True)
      axis.set_xticklabels(['0', 'testing', '10000', '20000', '30000'],fontsize=22)
    
    0 讨论(0)
  • 2020-11-22 08:16

    you can do:

    for k in ax.get_xmajorticklabels():
        if some-condition:
            k.set_color(any_colour_you_like)
    
    draw()
    
    0 讨论(0)
  • 2020-11-22 08:20

    This works:

    import matplotlib.pyplot as plt
    
    fig, ax1 = plt.subplots(1,1)
    
    x1 = [0,1,2,3]
    squad = ['Fultz','Embiid','Dario','Simmons']
    
    ax1.set_xticks(x1)
    ax1.set_xticklabels(squad, minor=False, rotation=45)
    

    0 讨论(0)
  • 2020-11-22 08:20

    This also works in matplotlib 3:

    x1 = [0,1,2,3]
    squad = ['Fultz','Embiid','Dario','Simmons']
    
    plt.xticks(x1, squad, rotation=45)
    
    0 讨论(0)
提交回复
热议问题