python语言绘图:绘制一组beta分布图

代码源自:

https://github.com/PacktPublishing/Bayesian-Analysis-with-Python

 

 

 

===========================================================

 

 

 

import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
import seaborn as sns
palette = 'muted'
sns.set_palette(palette); sns.set_color_codes(palette)

params = [0.5, 1, 2, 3]
x = np.linspace(0, 1, 100)
f, ax = plt.subplots(len(params), len(params), sharex=True,
  sharey=True)
for i in range(4):
    for j in range(4):
        a = params[i]
        b = params[j]
        y = stats.beta(a, b).pdf(x)
        ax[i,j].plot(x, y)
        ax[i,j].plot(0, 0, label="$\\alpha$ = {:3.2f}\n$\\beta$ = {:3.2f}".format(a, b), alpha=0)
        ax[i,j].legend(fontsize=12)
ax[3,0].set_xlabel('$\\theta$', fontsize=14)
ax[0,0].set_ylabel('$p(\\theta)$', fontsize=14)
plt.savefig('B04958_01_04.png', dpi=300, figsize=(5.5, 5.5))

plt.show()

 

 

 

 

 

 

 

 

 

绘图:

 

 

 

 

===========================================================

 
 
 

posted on 2022-06-09 13:36  Angry_Panda  阅读(291)  评论(0编辑  收藏  举报

导航