我遇到了一个错误:在绘制两个数组时,尽管我的x轴数组中没有任何负值,但我的x值却为负。我的x轴范围应从我的最小值0.005到最大值0.995。不应在此范围之外定义任何值。为什么我不知道为什么会这样?
print(xValsAppx)
print()
print(probabilityX)
plt.bar(xValsAppx, probabilityX)
plt.xlabel('Sample')
plt.ylabel('Probability of Observing the Sample')
plt.title('Normal Distribution for a = 0, b = 1')
xValsAppx在哪里
[0.005 0.015 0.025 0.035 0.045 0.055 0.065 0.075 0.085 0.095 0.105 0.115
0.125 0.135 0.145 0.155 0.165 0.175 0.185 0.195 0.205 0.215 0.225 0.235
0.245 0.255 0.265 0.275 0.285 0.295 0.305 0.315 0.325 0.335 0.345 0.355
0.365 0.375 0.385 0.395 0.405 0.415 0.425 0.435 0.445 0.455 0.465 0.475
0.485 0.495 0.505 0.515 0.525 0.535 0.545 0.555 0.565 0.575 0.585 0.595
0.605 0.615 0.625 0.635 0.645 0.655 0.665 0.675 0.685 0.695 0.705 0.715
0.725 0.735 0.745 0.755 0.765 0.775 0.785 0.795 0.805 0.815 0.825 0.835
0.845 0.855 0.865 0.875 0.885 0.895 0.905 0.915 0.925 0.935 0.945 0.955
0.965 0.975 0.985 0.995]
并且概率X为
[0.00977, 0.00995, 0.00999, 0.0, 0.00966, 0.01022, 0.01027, 0.01023, 0.0,
0.01046, 0.01008, 0.0, 0.00967, 0.0096, 0.0102, 0.01008, 0.00977, 0.0,
0.00961, 0.01003, 0.0095, 0.00944, 0.0106, 0.0, 0.0099, 0.0097,
0.01001,0.01017, 0.01014, 0.00977, 0.00998, 0.01013, 0.00978, 0.01017,
0.00939, 0.0, 0.00965, 0.0099, 0.01, 0.00973, 0.01009, 0.00968, 0.01003,
0.01009, 0.01022, 0.01022, 0.01022, 0.0, 0.01013, 0.00997, 0.00938, 0.0103,
0.00998, 0.00966, 0.01034, 0.00989, 0.0094, 0.0, 0.01071, 0.01065, 0.00945,
0.0098, 0.00997, 0.01, 0.0099, 0.01002, 0.00945, 0.00974, 0.01028, 0.01013,
0.01041, 0.00997, 0.01049, 0.0094, 0.00991, 0.00997, 0.01036, 0.01036,
0.00994, 0.01024, 0.01044, 0.01068, 0.00992, 0.0, 0.00996, 0.00955, 0.01014,
0.00991, 0.00977, 0.01013, 0.00989, 0.01027, 0.01037, 0.01016, 0.00957,
0.01001, 0.01004, 0.01054, 0.00946, 0.01005]
此处的图片:
答案 0 :(得分:1)
看docs,条的默认宽度为0.8
,不适合您的x值。尝试使用0.008
或0.01
。
plt.bar(xValsAppx, probabilityX, 0.008)