|
|
|||||||||||||||||||||||||||||
|
pylab_examples_Examples 93_hexbin_demo2. |
H.Kamifuji . |
|
hexbin は、axis メソッドまたは pyplot 関数です。これは基本的に、六角形のセルを持つ2次元ヒストグラムの pcolor です。 この事例は、Windows10_1909 で Python 3.9.0 環境では、動作しません。( Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) がデグレートしたのか? )
"""
hexbin is an axes method or pyplot function that is essentially a
pcolor of a 2-D histogram with hexagonal cells.
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
delta = 0.025
x = y = np.arange(-3.0, 3.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = Z2 - Z1 # difference of Gaussians
x = X.ravel()
y = Y.ravel()
z = Z.ravel()
if 1:
# make some points 20 times more common than others, but same mean
xcond = (-1 < x) & (x < 1)
ycond = (-2 < y) & (y < 0)
cond = xcond & ycond
xnew = x[cond]
ynew = y[cond]
znew = z[cond]
for i in range(20):
x = np.hstack((x, xnew))
y = np.hstack((y, ynew))
z = np.hstack((z, znew))
xmin = x.min()
xmax = x.max()
ymin = y.min()
ymax = y.max()
gridsize = 30
plt.subplot(211)
plt.hexbin(x, y, C=z, gridsize=gridsize, marginals=True, cmap=plt.cm.RdBu,
vmax=abs(z).max(), vmin=-abs(z).max())
plt.axis([xmin, xmax, ymin, ymax])
cb = plt.colorbar()
cb.set_label('mean value')
plt.subplot(212)
plt.hexbin(x, y, gridsize=gridsize, cmap=plt.cm.Blues_r)
plt.axis([xmin, xmax, ymin, ymax])
cb = plt.colorbar()
cb.set_label('N observations')
plt.show()
|
![]() Python 3.11.2 見直しました。上記のコードでは、下記のエラーが発生します。 Traceback (most recent call last): File "_:\hexbin_demo2.py", line 13, in <module> Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) ^^^^^^^^^^^^^^^^^^^^^ 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:\______\hexbin_demo2.py", line 13, inPython 3.12.0 (matplotlib 3.8.1) では、下記のようなエラーがあり、実行できない。 Traceback (most recent call last): File "E:\______\hexbin_demo2.py", line 13, in代替サンプルは、見つからない。 |
|
pylab_examples_Examples code: hexbin_demo2.py |
|