代码之家  ›  专栏  ›  技术社区  ›  Tom de Geus

用科学记数法给所有刻度标签上色

  •  0
  • Tom de Geus  · 技术社区  · 7 年前

    我想给左垂直轴的刻度标签上色。但是,以下代码:

    import matplotlib.pyplot as plt
    
    fig, ax = plt.subplots()
    
    ax.plot([1,5,10],[1,5,10])
    
    ax.set_xscale('log')
    ax.set_yscale('log')
    
    ax.set_xlim([1e0,1e1])
    ax.set_ylim([1e0,1e1])
    
    ax.yaxis.label.set_color('b')
    ax.spines['left'].set_edgecolor('b')
    ax.tick_params(axis='y', colors='b')
    
    plt.savefig('test.png')
    plt.show()
    

    无法为所有标签上色:

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  1
  •   Sheldore    7 年前

    使用

    ax.tick_params(axis='y', colors='b', which='both')
    

    哪里 both 对应于主刻度和次刻度。

    输出

    enter image description here