python生成柱状图 不显示_python – Matplotlib图表不显示在PyCharm中
我在PyCharm 3.4.1中運行以下代碼,并突出顯示%matplotlib內聯顯示語法錯誤,我刪除第一行,并運行,我希望它會提示我一些圖表,但它運行正常與Process完成退出代碼0,沒有圖表顯示.
我的問題是:
1.什么是%matplotlib在線使用;
2.如何讓pycharm顯示matplotlib圖表?
%matplotlib inline
from IPython.core.pylabtools import figsize
import numpy as np
from matplotlib import pyplot as plt
figsize(11, 9)
import scipy.stats as stats
dist = stats.beta
n_trials = [0, 1, 2, 3, 4, 5, 8, 15, 50, 500]
data = stats.bernoulli.rvs(0.5, size=n_trials[-1])
x = np.linspace(0, 1, 100)
# For the already prepared, I'm using Binomial's conj. prior.
for k, N in enumerate(n_trials):
sx = plt.subplot(len(n_trials) / 2, 2, k + 1)
plt.xlabel("$p$, probability of heads") \
if k in [0, len(n_trials) - 1] else None
plt.setp(sx.get_yticklabels(), visible=False)
heads = data[:N].sum()
y = dist.pdf(x, 1 + heads, 1 + N - heads)
plt.plot(x, y, label="observe %d tosses,\n %d heads" % (N, heads))
plt.fill_between(x, 0, y, color="#348ABD", alpha=0.4)
plt.vlines(0.5, 0, 4, color="k", linestyles="--", lw=1)
leg = plt.legend()
leg.get_frame().set_alpha(0.4)
plt.autoscale(tight=True)
plt.suptitle("Bayesian updating of posterior probabilities",
y=1.02,
fontsize=14)
plt.tight_layout()
總結
以上是生活随笔為你收集整理的python生成柱状图 不显示_python – Matplotlib图表不显示在PyCharm中的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 解决高并发的问题python_pytho
- 下一篇: 为什么多个线程不可能同时抢到一把锁_分布