简体   繁体   English

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

[英]Average point and standard deviation bars on scatter plot

If I have a scatter plot like this MWE: 如果我有像这样的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)

在此处输入图片说明

what's the easiest way to plot the 'average point' (is there a proper word for that?) on the plot? 在图上绘制“平均点”(是否有合适的词?)的最简单方法是什么? All of the tutorials and examples I've found show how to plot the line of best fit, but I just want the single point. 我发现的所有教程和示例都显示了如何绘制最佳拟合线,但我只想单点。

Plotting (x_ave, y_ave) works, but is there a better way, especially since I'd eventually want to show the standard deviations with error bars too? 绘制(x_ave, y_ave)(x_ave, y_ave) ,但是有没有更好的方法,特别是因为我最终还是想显示带有误差线的标准偏差?

If you want to plot a single scatter point with error bars, the best way would be to use the errorbar module. 如果要绘制带有误差线的单个散点,最好的方法是使用errorbar模块。 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. 以下答案显示了将其与误差条的自定义属性以及x和y的平均点的标准偏差均为1一起使用的示例。 You can specify your actual standard deviation values in xerr and yerr . 您可以在xerryerr指定实际的标准偏差值。 The error bars can be removed from the legend using this solution. 使用解决方案可以从图例中删除误差线。

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)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有最小值、最大值、平均值和标准偏差的箱线图 - Box plot with min, max, average and standard deviation 将散布数据转换为带有等于标准偏差的误差条的分箱数据 - turn scatter data into binned data with errors bars equal to standard deviation Python:多个文件中特定列的平均值和标准偏差,并使用标准偏差栏绘制平均值 - Python: average and standard deviation of specific columns among multiple files and plot the average with standard deviation bar Plotly (Python) 散点图 plot 显示平均值和标准差的气泡 - Plotly (Python) scatter plot that shows a bubble for mean and standard deviation Python Pylab散点图误差条(每个点上的误差是唯一的) - Python Pylab scatter plot error bars (the error on each point is unique) 绘制平均值和标准偏差 - Plot mean and standard deviation 如何在 numpy 和 matplotlib 中使用 Z23EEEB4347BDD26BDDFC6B7EE5 中的 plot 平均值和标准偏差一起在单个图表上 - How to plot average and standard deviation together on a single graph using numpy and matplotlib in python? 使用NumPy阵列执行分组平均值和标准差 - Performing grouped average and standard deviation with NumPy arrays 如何高效计算pyspark中的平均值和标准差 - How to efficiently calculate average and standard deviation in pyspark Pandas:按时钟时间计算平均值和标准偏差 - Pandas: compute average and standard deviation by clock time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM