How to fill area under step curve using pyplot?

后端 未结 1 418
温柔的废话
温柔的废话 2021-01-04 12:25

I have plotted two step curves using pyplot.step(), and I would like to shade in the area beneath these curves (ideally with transparent shading). pyplot.

1条回答
  •  时光取名叫无心
    2021-01-04 12:52

    You can use the alpha value of the fill_between to make it semi-transparent.

    import matplotlib.pyplot as plt
    import numpy as np
    
    x = np.linspace(0,50,35)
    y = np.random.exponential(1, len(x))
    y2 = np.random.exponential(1, len(x))
    
    plt.fill_between(x,y, step="pre", alpha=0.4)
    plt.fill_between(x,y2, step="pre", alpha=0.4)
    
    plt.plot(x,y, drawstyle="steps")
    plt.plot(x,y2, drawstyle="steps")
    
    plt.show()
    

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