Plot mean and standard deviation

前端 未结 2 1056
一向
一向 2020-12-07 14:23

I have several values of a function at different x points. I want to plot the mean and std in python, like the answer of this SO question. I know this must be easy using mat

2条回答
  •  萌比男神i
    2020-12-07 15:05

    plt.errorbar can be used to plot x, y, error data (as opposed to the usual plt.plot)

    import matplotlib.pyplot as plt
    import numpy as np
    
    x = np.array([1, 2, 3, 4, 5])
    y = np.power(x, 2) # Effectively y = x**2
    e = np.array([1.5, 2.6, 3.7, 4.6, 5.5])
    
    plt.errorbar(x, y, e, linestyle='None', marker='^')
    
    plt.show()
    

    plt.errorbar accepts the same arguments as plt.plot with additional yerr and xerr which default to None (i.e. if you leave them blank it will act as plt.plot).

    Example plot

提交回复
热议问题