Elegantly changing the color of a plot frame in matplotlib

后端 未结 3 1237
长发绾君心
长发绾君心 2020-12-08 00:34

This is a kind of follow-up question to this post, where the coloring of axes, ticks and labels was discussed. I hope it is alright to open a new, extended question for this

3条回答
  •  遥遥无期
    2020-12-08 01:28

    Assuming you're using a reasonably up-to-date version of matplotlib (>= 1.0), perhaps try something like this:

    import matplotlib.pyplot as plt
    
    # Make the plot...
    fig, axes = plt.subplots(nrows=2)
    axes[0].plot(range(10), 'r-')
    axes[1].plot(range(10), 'bo-')
    
    # Set the borders to a given color...
    for ax in axes:
        ax.tick_params(color='green', labelcolor='green')
        for spine in ax.spines.values():
            spine.set_edgecolor('green')
    
    plt.show()
    

    enter image description here

提交回复
热议问题