0

I'm getting this bug where, when plotting two arrays, I have negative x-values, despite there not being any negative values in my x-axis array. My x-axis should range from my minimum 0.005 to my max 0.995. There shouldn't be any values defined outside this range. Why am I getting I'm not sure why this is happening?

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')

where xValsAppx is

[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]

and probabilityX is

[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]

Image here:

enter image description here

2
  • please put you code as text, rather than as a figure. Commented May 13, 2019 at 6:13
  • please share your minimal code as well as your data too. Commented May 13, 2019 at 6:17

1 Answer 1

1

Looking at the docs, the default width of the bars is 0.8, which doesn't fit to your x values. Try e.g 0.008 or 0.01.

plt.bar(xValsAppx, probabilityX, 0.008)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.