On 2015-12-15 02:43, Robert wrote:
Hi,

When I run the following code, there is no figure shown in the end.


//////////
import pymc
import numpy as np

n = 5*np.ones(4,dtype=int)
x = np.array([-.86,-.3,-.05,.73])

alpha = pymc.Normal('alpha',mu=0,tau=.01)
beta = pymc.Normal('beta',mu=0,tau=.01)

@pymc.deterministic
def theta(a=alpha, b=beta):
     """theta = logit^{-1}(a+b)"""
     return pymc.invlogit(a+b*x)

d = pymc.Binomial('d', n=n, p=theta, value=np.array([0.,1.,3.,5.]),\
                     observed=True)
....
import pymc
import mymodel

S = pymc.MCMC(mymodel, db='pickle')
S.sample(iter=10000, burn=5000, thin=2)
pymc.Matplot.plot(S)



I find that the figures are shown after these two lines by myself:
*************
import matplotlib.pyplot as plt
plt.show()

I have searched around and have not found some explanation about it.
The plot function here is different from Matlab's. Is there better ways than
my last two lines? (I am not confident whether my last two lines is the
only choice.

No, that's right. pymc.Matplot.plot() uses matplotlib's pyplot API underneath. pyplot can run in two different modes: interactive and non-interactive. When used in a standalone script, like I assume here, it defaults to non-interactive. That means that it will not raise any plot windows until you call plt.show().

  http://matplotlib.org/faq/usage_faq.html#what-is-interactive-mode

See any of the examples here (note: "pylab" is the essentially the same as "pyplot" for these purposes):

  http://matplotlib.org/examples/pylab_examples/index.html

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to