How can I set the background color on specific areas of a pyplot figure?

前端 未结 1 655
春和景丽
春和景丽 2020-12-07 18:44

I\'ve managed to plot a series of points with the following code:

plt = pp.figure()
for i in range(spt.shape[1]):
    spktrain = spt[0,i]
    for trial in sp         


        
相关标签:
1条回答
  • 2020-12-07 19:46

    You can use axhspan and/or axvspan like this:

    import matplotlib.pyplot as plt
    
    plt.figure()
    plt.xlim(0, 5)
    plt.ylim(0, 5)
    
    for i in range(0, 5):
        plt.axhspan(i, i+.2, facecolor='0.2', alpha=0.5)
        plt.axvspan(i, i+.5, facecolor='b', alpha=0.5)
    
    plt.show()
    

    enter image description here

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