Matplotlib: Changing the color of an axis

后端 未结 3 1192
青春惊慌失措
青春惊慌失措 2020-11-27 14:29

Is there a way to change the color of an axis (not the ticks) in matplotlib? I have been looking through the docs for Axes, Axis, and Artist, but no luck; the matplotlib gal

3条回答
  •  萌比男神i
    2020-11-27 14:37

    When using figures, you can easily change the spine color with:

    ax.spines['bottom'].set_color('#ffffdffffd')
    ax.spines['top'].set_color('#ffffdffffd') 
    ax.spines['right'].set_color('red')
    ax.spines['left'].set_color('red')
    

    Use the following to change only the ticks:

    ax.tick_params(axis='x', colors='red')
    ax.tick_params(axis='y', colors='red')
    

    And the following to change only the label:

    ax.yaxis.label.set_color('red')
    ax.xaxis.label.set_color('red')
    

    And finally the title:

    ax.title.set_color('red')
    

提交回复
热议问题