Step function in matplotlib

前端 未结 2 495
你的背包
你的背包 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:37

    It's not clear exactly what you're trying to do, but I think this may produce the plot you are looking for. If this is not what you are looking for it will be easier to assist you with more information.

    import numpy as np
    import matplotlib.pyplot as plt
    
    x = np.linspace(0,5,4)
    y = [1,1,-1,1]
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.step(x,y)
    ax.set_xlabel('Time (s)')
    ax.set_ylabel(r'Jerk ($m/s^3$)')
    ax.set_ylim((-1.5,1.5))
    ax.set_title('Jerk Produced by the Engine')
    
    plt.show()
    

    Example Plot

提交回复
热议问题