|
|
|||||||||||||||||||||||||||||
|
matplotlib frontpage_Examples 02_plot_contour. |
H.Kamifuji . |
|
この例では、フロントページの輪郭の例を再現しています。 この事例は、Windows10_1909 で Python 3.9.0 環境では、動作しません。( module 'matplotlib.mlab' has no attribute 'bivariate_normal'が 3.1 から削除されたのか? )
"""
=========================
Frontpage contour example
=========================
This example reproduces the frontpage contour example.
"""
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import mlab, cm
extent = (-3, 3, -3, 3)
delta = 0.5
x = np.arange(-3.0, 4.001, delta)
y = np.arange(-4.0, 3.001, delta)
X, Y = np.meshgrid(x, y)
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, -0.5)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = (Z1 - Z2) * 10
levels = np.linspace(-2.0, 1.601, 40)
norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max())
fig, ax = plt.subplots()
cset1 = ax.contourf(
X, Y, Z, levels,
norm=norm)
ax.set_xlim(-3, 3)
ax.set_ylim(-3, 3)
ax.set_xticks([])
ax.set_yticks([])
fig.savefig("contour_frontpage.png", dpi=25) # results in 160x120 px image
|
![]() Python 3.11.2 見直しました。上記のコードでは、下記のエラーが発生します。 Traceback (most recent call last): File "_:\plot_contour.py", line 19, in <module> Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, -0.5) ^^^^^^^^^^^^^^^^^^^^^ AttributeError: module 'matplotlib.mlab' has no attribute 'bivariate_normal' matplotlib 内部のエラーのようです。matplotlib の改修(先祖帰りバグの改修)を待つしかない。 Python 3.11.6 (matplotlib 3.7.1) では、下記のようなエラーがあり、実行できない。 Traceback (most recent call last): File "M:\______\plot_contour.py", line 19, inPython 3.12.0 (matplotlib 3.8.1) では、下記のようなエラーがあり、実行できない。 Traceback (most recent call last): File "E:\______\plot_contour.py", line 19, in代替サンプルは、見つけられない。 |
| frontpage_Examples code: plot_contour.py |
|