matplotlib ticks position relative to axis

后端 未结 2 718
南旧
南旧 2020-12-08 15:58

Is there a way in matplotlib to set ticks between the labels and the axis as it is by default in Origin? The examples section online does not show a single plot with this fe

相关标签:
2条回答
  • 2020-12-08 16:39

    I guess you need this:

    By getting the subplot object you can play with your ticks

    ax = plt.subplot(111)
    yax = ax.get_yaxis()
    plt.xticks(y_pos, city)
    xtickNames=ax.set_xticklabels(city)
    plt.setp(xtickNames, rotation=45, fontsize=10)
    

    Following is the output with 45 degrees rotated ticks

    0 讨论(0)
  • 2020-12-08 16:59

    To set the just the major ticks:

    ax = plt.gca()
    ax.get_yaxis().set_tick_params(direction='out')
    ax.get_xaxis().set_tick_params(direction='out')
    plt.draw()
    

    to set all ticks (minor and major),

    ax.get_yaxis().set_tick_params(which='both', direction='out')
    ax.get_xaxis().set_tick_params(which='both', direction='out')
    plt.draw()
    

    to set both the x and y axis at the same time:

    ax = plt.gca()
    ax.tick_params(direction='out')
    

    axis level doc and axes level doc

    To shift the tick labels relative to the ticks use pad. Compare

    ax.tick_params(direction='out', pad=5)
    plt.draw()
    

    with

    ax.tick_params(direction='out', pad=15)
    plt.draw()
    
    0 讨论(0)
提交回复
热议问题