Ich möchte die Birthday Problem mit anderen n
visualisieren. Mein Ziel ist es, mehrere Grafiken in der gleichen Figur zu zeichnen, aber es funktioniert nicht. Es zeichnet nur die letzte Grafik auf und ignoriert die anderen. Ich benutze das Jupyter Notebook. Das ist mein Code:Plotten mehrerer Grafiken funktioniert nicht mit pylab
from decimal import Decimal
def calc_p_distinct(n):
p_distinct = numpy.arange(0, n.size, dtype=Decimal)
for i in n:
p_distinct[i] = Decimal(1.0)
for i in n:
for person in range(i):
p_distinct[i] = Decimal(p_distinct[i]) * Decimal(((Decimal(365-person))/Decimal(365)))
return p_distinct
# n is the number of people
n = numpy.arange(0, 20)
n2 = numpy.arange(0, 50)
n3 = numpy.arange(0, 100)
# plot the probability distribution
p_distinct = calc_p_distinct(n)
pylab.plot(n, p_distinct, 'r')
p_distinct2 = calc_p_distinct(n2)
pylab.plot(n2, p_distinct2, 'g')
p_distinct3 = calc_p_distinct(n3)
pylab.plot(n3, p_distinct3, 'b')
# set the labels of the axis and title
pylab.xlabel("n", fontsize=18)
pylab.ylabel("probability", fontsize=18)
pylab.title("birthday problem", fontsize=20)
# show grid
pylab.grid(True)
# show the plot
pylab.show()
Wenn ich einer der calc_p_distinct() Funktion ersetzen Anrufe mit einer anderen integrierten Funktion (z numpy.sin (n)), es mir zwei Graphen zeigen. Daraus schließe ich, dass es etwas mit meiner Funktion zu tun haben muss. Was mache ich hier falsch?
Ahh! Mein Fehler, du hast absolut recht, vielleicht war es zu spät, als ich das getan habe: D Danke! –