|
|
|||||||||||||||||||||||||||||
|
matplotlib style_sheets_Examples 69_plot_bmh. |
H.Kamifuji . |
|
ハッカーのためのベイジアンメソッドスタイルシート この例では、Bayesian Methods for Hackers オンラインブックで使用されるスタイルを示します。 http://camdavidsonpilon.github.io/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/ この事例は、Windows10_1909 で Python 3.9.0 環境では、動作しません。( plot_beta_hist(ax, 10, 10) がデグレートしたのか? )
"""
========================================
Bayesian Methods for Hackers style sheet
========================================
This example demonstrates the style used in the Bayesian Methods for Hackers
[1]_ online book.
.. [1] http://camdavidsonpilon.github.io/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/
"""
from numpy.random import beta
import matplotlib.pyplot as plt
plt.style.use('bmh')
def plot_beta_hist(ax, a, b):
ax.hist(beta(a, b, size=10000), histtype="stepfilled",
bins=25, alpha=0.8, normed=True)
fig, ax = plt.subplots()
plot_beta_hist(ax, 10, 10)
plot_beta_hist(ax, 4, 12)
plot_beta_hist(ax, 50, 12)
plot_beta_hist(ax, 6, 55)
ax.set_title("'bmh' style sheet")
plt.show()
|
![]() Python 3.11.2 見直しました。上記のコードでは、下記のエラーが発生します。 plot_bmh.txt matplotlib 内部のエラーのようです。matplotlib の改修(先祖帰りバグの改修)を待つしかない。 Python 3.11.6 (matplotlib 3.7.1) では、下記のようなエラーがあり、実行できない。 Traceback (most recent call last): File "M:\______\plot_bmh.py", line 25, inPython 3.12.0 (matplotlib 3.8.1) では、下記のようなエラーがあり、実行できない。 Traceback (most recent call last): File "E:\______\plot_bmh.py", line 25, inPython 3.11.6 (matplotlib 3.7.1) 及び Python 3.12.0 (matplotlib 3.8.1) で、見直し中、新しいサンプル(style-sheets-bmh-py) を見つけ、下記のコードで、正常に実行できました。
"""
========================================
Bayesian Methods for Hackers style sheet
========================================
This example demonstrates the style used in the Bayesian Methods for Hackers
[1]_ online book.
.. [1] http://camdavidsonpilon.github.io/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/
"""
import matplotlib.pyplot as plt
import numpy as np
# Fixing random state for reproducibility
np.random.seed(19680801)
plt.style.use('bmh')
def plot_beta_hist(ax, a, b):
ax.hist(np.random.beta(a, b, size=10000),
histtype="stepfilled", bins=25, alpha=0.8, density=True)
fig, ax = plt.subplots()
plot_beta_hist(ax, 10, 10)
plot_beta_hist(ax, 4, 12)
plot_beta_hist(ax, 50, 12)
plot_beta_hist(ax, 6, 55)
ax.set_title("'bmh' style sheet")
plt.show()
Python 3.11.6 (matplotlib 3.7.1) 及び Python 3.12.0 (matplotlib 3.8.1) 共に、正常実行です。![]() |
|
style_sheets_Examples code: plot_bmh.py style-sheets-bmh-py |
|