Python 绘制平均值和标准差

Python 绘制平均值和标准差,python,matplotlib,plot,Python,Matplotlib,Plot,一个函数在不同的x点有几个值。我想用python绘制mean和std,就像的答案一样。我知道使用matplotlib一定很容易,但我不知道可以实现这一点的函数名。有人知道吗 可用于绘制x、y、错误数据(与通常的plt.plot相反) plt.errorbar接受与plt.plot相同的参数,并附加默认为无的yerr和xerr(即,如果将其保留为空,它将充当plt.plot) 您可以通过以下示例找到答案: 图中是这样的: 如果您在此处发布相关代码,而不仅仅是一个链接,那将非常好。要在蜡烛的顶部和底

一个函数在不同的x点有几个值。我想用python绘制mean和std,就像的答案一样。我知道使用matplotlib一定很容易,但我不知道可以实现这一点的函数名。有人知道吗

可用于绘制x、y、错误数据(与通常的
plt.plot
相反)

plt.errorbar
接受与
plt.plot
相同的参数,并附加默认为无的
yerr
xerr
(即,如果将其保留为空,它将充当
plt.plot


您可以通过以下示例找到答案:

图中是这样的:


如果您在此处发布相关代码,而不仅仅是一个链接,那将非常好。要在蜡烛的顶部和底部添加这些小水平线,请指定“翻转”选项。例如,到plt.errorbar(x,y,E,linestyle='None',marker='^',翻覆=3)
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()
"""
Demo of errorbar function with different ways of specifying error bars.

Errors can be specified as a constant value (as shown in `errorbar_demo.py`),
or as demonstrated in this example, they can be specified by an N x 1 or 2 x N,
where N is the number of data points.

N x 1:
    Error varies for each point, but the error values are symmetric (i.e. the
    lower and upper values are equal).

2 x N:
    Error varies for each point, and the lower and upper limits (in that order)
    are different (asymmetric case)

In addition, this example demonstrates how to use log scale with errorbar.
"""
import numpy as np
import matplotlib.pyplot as plt

# example data
x = np.arange(0.1, 4, 0.5)
y = np.exp(-x)
# example error bar values that vary with x-position
error = 0.1 + 0.2 * x
# error bar values w/ different -/+ errors
lower_error = 0.4 * error
upper_error = error
asymmetric_error = [lower_error, upper_error]

fig, (ax0, ax1) = plt.subplots(nrows=2, sharex=True)
ax0.errorbar(x, y, yerr=error, fmt='-o')
ax0.set_title('variable, symmetric error')

ax1.errorbar(x, y, xerr=asymmetric_error, fmt='o')
ax1.set_title('variable, asymmetric error')
ax1.set_yscale('log')
plt.show()