散点图上的平均点和标准偏差条

Average point and standard deviation bars on scatter plot

如果我有这样的散点图 MWE:

import numpy as np
import matplotlib.pyplot as plt

np.random.seed(5)
fig = plt.figure()
ax = fig.add_subplot(111)
xlist = []
ylist = []
for i in range(500):
    x = np.random.normal(100)
    xlist.append(x)
    y = np.random.normal(5)
    ylist.append(y)

x_ave = np.average(x)
y_ave = np.average(y)
plt.scatter(xlist, ylist)
plt.scatter(x_ave, y_ave, c = 'red', marker = '*', s = 50)

在地块上绘制 'average point'(有合适的​​词吗?)的最简单方法是什么?我找到的所有教程和示例都展示了如何绘制最佳拟合线,但我只想要单点。

绘图 (x_ave, y_ave) 可行,但是否有更好的方法,特别是因为我最终也想用误差线显示标准偏差?

如果您想绘制带有误差条的单个散点,最好的方法是使用 errorbar module. The following answer shows an example of using it with customized properties of error bars and the average point with a standard deviation of 1 for both x and y. You can specify your actual standard deviation values in xerr and yerr. The error bars can be removed from the legend using this 解决方案。

plt.scatter(xlist, ylist)

plt.errorbar(x_ave, y_ave, yerr=1, xerr=1, fmt='*', color='red', ecolor='black', ms=20, 
             elinewidth=4, capsize=10, capthick=4, label='Average')

handles, labels = ax.get_legend_handles_labels()
handles = [h[0] for h in handles]
ax.legend(handles, labels, loc='best', fontsize=16)