1

I have taking probability using randint function. but i am facing issue in histogram to show my probability. Also attaching snap which i am getting error my Probability output like this.

{60: 0.013, 6: 0.016, 99: 0.01, 25: 0.006, 45: 0.017, 51: 0.009, 72: 0.011, 8: 0.015, 10: 0.015, 82: 0.011, 50: 0.014, 43: 0.012, 52: 0.011, 74: 0.015, 12: 0.015, 39: 0.01, 89: 0.014, 7: 0.009}

My python code.

from collections import Counter
import numpy as np
import matplotlib.pyplot as plt

hist = np.random.randint(low=1, high=100, size=1000)
counts = Counter(hist)
total = sum(counts.values())
hist = {k:v/total for k,v in counts.items()}


num_bins = 10
n, bins, patches = plt.hist(hist, num_bins, normed=1, facecolor='blue', alpha=0.5)
#plt.plot(bins, hist, 'r--')
plt.xlabel('Grades')
plt.ylabel('Probability')
plt.title('Histogram of Students Grade')
plt.subplots_adjust(left=0.15)
plt.show()
5
  • Why is this tagged R? Commented Dec 12, 2019 at 18:23
  • It was mistake. i comment this plt.plot(bins, hist, 'r--') i need just my Probabilty Histogram. where the issue occurs ? Commented Dec 12, 2019 at 21:14
  • What is the problem exactly? Can you show us the plot you are getting now and explain what it is that you want to look different? Commented Dec 13, 2019 at 12:39
  • @FranciscaConcha-Ramírez when you run this code i am getting this error '<' not supported between instances of 'dict' and 'float'. and the graph was empty. Commented Dec 13, 2019 at 15:20
  • @FranciscaConcha-Ramírez i think their will use Dict and float function to seprate the values first then do the Histogram. like {60: 0.013, 6: 0.016, 99: 0.01} do you understand my issue ? Commented Dec 13, 2019 at 15:32

1 Answer 1

2

If you just comment out plt.plot(bins, hist, 'r--') you get this plot:

enter image description here

Is this what you are looking for?

If you want to make use of n, bins and patches you can refer to this example in the Matplotlib documentation.

Sign up to request clarification or add additional context in comments.

4 Comments

Actually, i need just my Probabilty Histogram.. can you Edit my code ?
I'm not sure I understand you correctly. Isn't this exactly what the graph shows?
this is my output of probabilty {60: 0.013, 6: 0.016, 99: 0.01, 25: 0.006, 45: 0.017, 51: 0.009, 72: 0.011, 8: 0.015, 10: 0.015, 82: 0.011} now i want graph in x-axis and y-axis. like 60 in y-axis and 0.013 in x-axis in graph.
i am facing this error TypeError: '<' not supported between instances of 'dict' and 'float'

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.