|
|
|||||||||||||||||||||||||||||
|
matplotlib frontpage_Examples 03_plot_histogram. |
H.Kamifuji . |
|
この例では、フロントページのヒストグラムの例を再現しています。 この事例は、Windows10_1909 で Python 3.9.0 環境では、動作しません。( 'Rectangle' object has no property 'normed'が 3.1 から削除されたのか? )
"""
===========================
Frontpage histogram example
===========================
This example reproduces the frontpage histogram example.
"""
import matplotlib.pyplot as plt
import numpy as np
random_state = np.random.RandomState(19680801)
X = random_state.randn(10000)
fig, ax = plt.subplots()
ax.hist(X, bins=25, normed=True)
x = np.linspace(-5, 5, 1000)
ax.plot(x, 1 / np.sqrt(2*np.pi) * np.exp(-(x**2)/2), linewidth=4)
ax.set_xticks([])
ax.set_yticks([])
fig.savefig("histogram_frontpage.png", dpi=25) # results in 160x120 px image
|
![]() Python 3.11.2 見直しました。上記のコードでは、下記のエラーが発生します。 Traceback (most recent call last): File "_:\plot_histogram.py", line 17, in <module> ax.hist(X, bins=25, normed=True) File "C:\Users\kamif\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\__init__.py", line 1459, in inner return func(ax, *map(sanitize_sequence, args), **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\kamif\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\axes\_axes.py", line 6943, in hist p._internal_update(kwargs) File "C:\Users\kamif\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\artist.py", line 1223, in _internal_update return self._update_props( ^^^^^^^^^^^^^^^^^^^ File "C:\Users\kamif\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\artist.py", line 1197, in _update_props raise AttributeError( AttributeError: Rectangle.set() got an unexpected keyword argument 'normed' matplotlib 内部のエラーのようです。matplotlib の改修(先祖帰りバグの改修)を待つしかない。 Python 3.11.6 (matplotlib 3.7.1) では、下記のようにエラーがあり、実行できない。 Traceback (most recent call last): File "M:\______\plot_histogram.py", line 17, inPython 3.12.0 (matplotlib 3.8.1) では、下記のようにエラーがあり、実行できない。 Traceback (most recent call last): File "E:\______\plot_histogram.py", line 17, in代替サンプルは、見つけられない。 |
| frontpage_Examples code: plot_histogram.py |
|