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

后端 未结 5 1924
感动是毒
感动是毒 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:27

    If you have non-uniformly spaced data points, you can use the drawstyle keyword argument for plot:

    x = [1,2.5,3.5,4] 
    y = [0.002871972681775004, 0.00514787917410944, 
         0.00863476098280219, 0.012003316194034325]
    
    plt.plot(x, y, drawstyle='steps-pre')
    

    Also available are steps-mid and steps-post.

提交回复
热议问题