I am trying to draw histogram but nothing appears in the Figure Window. My code is below:
import numpy as np
import matplotlib.pyplot as plt
values = [1000000, 1525097, 2050194, 1095638, 1620736, 2145833, 1191277, 1716375, 1286916, 1382555]
plt.hist(values, 10, histtype = 'bar', facecolor = 'blue')
plt.ylabel("Values")
plt.xlabel("Bin Number")
plt.title("Histogram")
plt.axis([0,11,0,220000])
plt.show()
This is the output:
I am trying to achieve this plot
Any help would be much appreciated...
You are confusing what a histogram is. The histogram that can be produced with the given data is as given below.
A histogram basically counts how many given values fall within a given range.
You have given incorrect arguments to the axis() function. The ending value is 2200000
You missed a single zero. Also you have swapped the arguments. Limits of the x axis comes first and then the limits of the Y axis. This is the modified code:
import numpy as np
import matplotlib.pyplot as plt
values = [1000000, 1525097, 2050194, 1095638, 1620736, 2145833, 1191277, 1716375, 1286916, 1382555]
plt.hist(values, 10, histtype = 'bar', facecolor = 'blue')
plt.ylabel("Values")
plt.xlabel("Bin Number")
plt.title("Histogram")
plt.axis([0,2200000,0,11])
plt.show()
This is the histogram generated:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With