Step function in matplotlib

前端 未结 2 494
你的背包
你的背包 2020-12-12 05:22

I have seen some questions asked about step functions in matplotlib but this one is different. Here is my function:

def JerkFunction(listOfJerk):
    \'\'\'R         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-12 05:50

    I think you are having the same problem this question Matlibplot step function index 0. The issue you are having is related to where step changes the value in relation to the x values (doc).

    The following demonstrates the three ways it can do this. The curves are shifted vertically for clarity. The horizontal dashed lines are 'zero' and the vertical dotted lines are your x values.

    x = np.linspace(0,5,3)
    y = np.array([1,-1,1])
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.step(x,y,color='r',label='pre')
    ax.step(x,y+3,color='b',label='post',where='post')
    ax.step(x,y+6,color='g',label='mid',where='mid')
    for j in [0,3,6]:
        ax.axhline(j,color='k',linestyle='--')
    for j in x:
        ax.axvline(j,color='k',linestyle=':')
    ax.set_ylim([-2,9])
    ax.set_xlim([-1,6])
    ax.legend()
    
    ax.draw()
    

    example of three step location options

提交回复
热议问题