How do I plot a step function with Matplotlib in Python?

后端 未结 5 1922
感动是毒
感动是毒 2020-12-09 02:32

This should be easy but I have just started toying with matplotlib and python. I can do a line or a scatter plot but i am not sure how to do a simple step function. Any help

5条回答
  •  情书的邮戳
    2020-12-09 03:22

    It seems like you want step.

    E.g.

    import matplotlib.pyplot as plt
    
    x = [1,2,3,4] 
    y = [0.002871972681775004, 0.00514787917410944, 
         0.00863476098280219, 0.012003316194034325]
    
    plt.step(x, y)
    plt.show()
    

    enter image description here

提交回复
热议问题