0
を別のn
で視覚化したいと思います。私の目的は、複数のグラフを同じ図形にプロットすることですが、それは機能しません。最後のグラフだけをプロットし、他のグラフは無視します。ジュピターノートを使用しています。私は別の組み込み関数で(例えばnumpy.sin(n))は、それは私に二つのグラフが表示されます呼び出すcalc_p_distinct()関数の一つ交換するとき複数のグラフをプロットするのが円滑ではない
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()
: は、これは私のコードです。だから、私はそれが私の機能と何か関係があると結論づけます。私はここで間違って何をしていますか?
ああ!私の悪い、あなたは絶対に正しいです、多分それは私がこれをしたときに遅かった:Dありがとう! –