gpt4 book ai didi

python - matplotlib/python - 如何绘制这样的图?平均值 ± 3* 标准偏差

转载 作者:太空宇宙 更新时间:2023-11-04 05:26:08 25 4
gpt4 key购买 nike

我想要这样的图片: enter image description here

x轴上下限已给定,远大于/小于给定数据。

我找到的所有图都只有 ± 1* 标准差。

我也不确定如何像这样修复 x 轴。

我的数据是一个 float 的 python 列表。

现在,我只有三个点,但我希望在它们之间有一条线,并且在这些点处有一条垂直线。x 轴也不正确。

plt.figure()
x = []
for item in circ_list:
x.append(float(item))
mean = np.mean(x)
std = np.std(x)
target_upper_bound = mean + 3 * std
target_lower_bound = mean - 3 * std

total_intermid = wear_limit[1] - wear_limit[0]
ten_percent_intermid = total_intermid / 10.0
plt.gca().axes.get_yaxis().set_visible(False)
plt.xlim([wear_limit[0], wear_limit[1]])

plt.plot(x, np.zeros_like(x), 'x')
plt.plot(np.array([mean, mean + 2 * std, mean - 2 * std]),
np.zeros_like(np.array([mean, mean + 2 * std, mean - 2 * std])), '|')

for i in x:
plt.annotate(str(i), xy=(i, 0))
plt.annotate('mean', xy=(mean, 0))
plt.annotate('mean+3*std', xy=(target_upper_bound, 0))
plt.annotate('mean-3*std', xy=(target_lower_bound, 0))
plt.show()

最佳答案

不确定我是否完全理解您的尝试。看看这个例子,它是否做了类似于你想要的事情?

import numpy as np
import matplotlib.pyplot as plt

#create random data
data=np.random.random(100)
std=np.std(data)

#display the individual data points
plt.scatter(data,np.zeros(data.shape[0]))

#use errorbar function to create symmetric horizontal error bar
#xerr provides error bar length
#fmt specifies plot icon for mean value
#ms= marker size
#mew = marker thickness
#capthick = thickness of error bar end caps
#capsize = size of those caps

plt.errorbar(np.mean(data),0,xerr=3*std,fmt='|', ms=30,mew=2,capthick=2,capsize=10)

#set x axis limits
plt.xlim([-10,10])

关于python - matplotlib/python - 如何绘制这样的图?平均值 ± 3* 标准偏差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38620828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com