Reputation: 71
In the below code, I generate random numbers and then taking the probability and create the graph. now how can I make the graph two times like I want to generate the random numbers again and create graph again.
#!/usr/bin/env python3
from collections import Counter
import numpy as np
import matplotlib.pyplot as plt
#Random Number Generating
x = np.random.randint(low=1, high=100, size=100000)
counts = Counter(x)
total = sum(counts.values())
d1 = {k:v/total for k,v in counts.items()}
grad = d1.keys()
prob = d1.values()
print(str(grad))
print(str(prob))
#bins = 20
plt.hist(prob,bins=20, normed=1, facecolor='blue', alpha=0.5)
#plt.plot(bins, hist, 'r--')
plt.xlabel('Probability')
plt.ylabel('Number Of Students')
plt.title('Histogram of Students Grade')
plt.subplots_adjust(left=0.15)
plt.show()
Upvotes: 0
Views: 173
Reputation: 118
You can call the function as much as you need!
import numpy as np
import matplotlib.pyplot as plt
from collections import Counter
def my_funct():
np.random.seed(1223) # fixing the seed! but I don't think you need it
#Random Number Generating
x = np.random.randint(low=1, high=100, size=100000)
counts = Counter(x)
total = sum(counts.values())
d1 = {k:v/total for k,v in counts.items()}
grad = d1.keys()
prob = d1.values()
print(str(grad))
print(str(prob))
#bins = 20
plt.hist(prob,bins=20, normed=1, facecolor='blue', alpha=0.5)
#plt.plot(bins, hist, 'r--')
plt.xlabel('Probability')
plt.ylabel('Number Of Students')
plt.title('Histogram of Students Grade')
plt.subplots_adjust(left=0.15)
plt.show()
#calling the function twice
my_funct()
my_funct()
Upvotes: 1