这可能是一个愚蠢的问题,但是每当我使用.plot()函数时,它都会绘制两次摘要。谁知道,为什么它会这样做,我怎么才能阻止它?

如你所见,我正在使用jupyter笔记本。
任何stan模型都会发生这种情况(并且在两个单独的安装上)
这段代码将为我产生问题
import pystan
import numpy as np
model_string = """
data {
int<lower=0> N;
int y[N];
}
parameters {
real<lower=0, upper=1> theta;
}
model {
theta ~ beta(1,1);
y ~ bernoulli(theta);
}
"""
N = 50
z = 10
y = np.append(np.repeat(1, z), np.repeat(0, N - z))
dat = {'y':y,
'N':N}
fit = pystan.stan(model_code=model_string, data=dat, iter=1000, warmup=200, thin=1, chains = 3)
fit.plot()发布于 2016-07-19 06:54:02
这是由于%matplotlib inline语句绘制的内容比您希望的要多。StanFit4Model.plot方法调用matplotlib.pyplot.subplot,当您的笔记本有%matplotlib inline时,该调用本身将绘制一个图。然后该方法返回Figure对象。如果您没有捕捉到它,您的笔记本决定将其显示为图像,而不是打印文字,您将得到双倍图。
您可以通过捕获输出Figure来输出单个绘图。更改您的代码
fit.plot()取而代之
fig = fit.plot()发布于 2018-09-03 19:21:31
在`.plot()‘后面加一个分号也可以解决这个问题。
https://stackoverflow.com/questions/37646860
复制相似问题