Matplotlib axvspan - solid fill?

后端 未结 1 762
礼貌的吻别
礼貌的吻别 2021-01-03 15:07

I\'m using this line of code to create a vertical span across a graph using matplotlib.

matplotlib.pyplot.axvspan(datetime.datetime.strptime(\"09-10-2015\",          


        
相关标签:
1条回答
  • 2021-01-03 15:52

    It's not about transparency (which you can change with the alpha parameter). It's about zorder (a kind of distance to the user, lower zorder will be farther). You need to put the zorder of the grid below the zorder of the axvspan (which in turn should be below, I think, of the plot). Check the following example:

    import numpy as np
    import matplotlib.pyplot as plt
    
    t = np.arange(-1, 2, .01)
    s = np.sin(2*np.pi*t)
    
    plt.plot(t, s,zorder=4)
    
    p = plt.axvspan(1.25, 1.55, facecolor='g', alpha=1,zorder=3)
    
    plt.axis([-1, 2, -1, 2])
    plt.grid(zorder=2)
    
    plt.show()
    

    , which results in:

    0 讨论(0)
提交回复
热议问题