Hi all,
I am trying to plot the time evolution of a probability distribution, but I
don't know how to use it. I have a different histogram for each time step.
I tried plt.ion() but I'm not sure how to use it. I'm sure it must be a
simple solution, but I haven't really found out how to do it! If I use
plt.show() as written below, I have to close the window every time for it
to reopen. Here is my code, can you help me?
import matplotlib.pyplot as plt
import numpy
import math
def p(N, Na, fa, fb):
return float(Na)*fa/(Na*fa + (N-Na)*fb)
def binomial(n,k):
if k > n-k:
k = n-k
accum = 1
for i in range(1,k+1):
accum *= (n - (k - i))
accum /= i
return accum
def pk(N, k, p):
return binomial(N, k)*math.pow(p,k)*math.pow((1-p),(N-k))
def expected(N, dist):
soma = 0
for k in range(N + 1):
soma += k*dist[k]
return soma
def drawhist(menMeans):
N = len(menMeans)
ind = numpy.arange(N)
width = 1.0
plt.clf()
plt.ylabel('Probability')
plt.xlabel('k')
plt.xlim(0.0,N)
plt.ylim(0.0,1.0)
plt.bar(ind, menMeans, width)
plt.draw()
plt.show()
N = 100
Na = 50
fa = 10
fb = 5
pks = [0]*(N+1)
pks[Na] = 1
pkst = [0]*(N+1)
expect = [Na]
drawhist(pks)
p = [p(N, n, fa, fb) for n in range(N + 1)]
for t in range(5):
for Na in range(N + 1):
for k in range(N + 1):
pkst[k] += pks[Na]*pk(N, k, p[Na])
drawhist(pkst)
pks = pkst
pkst = [0]*(N+1)
expect.append(expected(N, pks))
------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13.
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users