Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100445 > unrolled thread

Question about figure plot

Started byRobert <rxjwg98@gmail.com>
First post2015-12-14 18:43 -0800
Last post2015-12-15 15:22 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Question about figure plot Robert <rxjwg98@gmail.com> - 2015-12-14 18:43 -0800
    Re: Question about figure plot Robert Kern <robert.kern@gmail.com> - 2015-12-15 15:22 +0000

#100445 — Question about figure plot

FromRobert <rxjwg98@gmail.com>
Date2015-12-14 18:43 -0800
SubjectQuestion about figure plot
Message-ID<ba4b4615-2739-49b3-9bb3-eafc527ddebc@googlegroups.com>
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.

Thanks,

[toc] | [next] | [standalone]


#100463

FromRobert Kern <robert.kern@gmail.com>
Date2015-12-15 15:22 +0000
Message-ID<mailman.24.1450192941.22044.python-list@python.org>
In reply to#100445
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web