|
|
matplotlib api_Examples 12_demo_affine_image. |
H.Kamifuji . |
draw_image をサポートするバックエンドで任意のアフィン変換(例:agg、ps バックエンド)を使用すると、出力のイメージは、その境界が破線の黄色の長方形に一致する必要があります。 この事例は、Windows10_1909 で Python 3.9.0 環境では、動作しません。( Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) がデグレートしたのか? ) """ ============================ Affine transform of an image ============================ For the backends that support draw_image with optional affine transform (e.g., agg, ps backend), the image of the output should have its boundary match the dashed yellow rectangle. """ import numpy as np import matplotlib.mlab as mlab import matplotlib.pyplot as plt import matplotlib.transforms as mtransforms def get_image(): delta = 0.25 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 return Z def do_plot(ax, Z, transform): im = ax.imshow(Z, interpolation='none', origin='lower', extent=[-2, 4, -3, 2], clip_on=True) trans_data = transform + ax.transData im.set_transform(trans_data) # display intended extent of the image x1, x2, y1, y2 = im.get_extent() ax.plot([x1, x2, x2, x1, x1], [y1, y1, y2, y2, y1], "y--", transform=trans_data) ax.set_xlim(-5, 5) ax.set_ylim(-4, 4) # prepare image and figure fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2) Z = get_image() # image rotation do_plot(ax1, Z, mtransforms.Affine2D().rotate_deg(30)) # image skew do_plot(ax2, Z, mtransforms.Affine2D().skew_deg(30, 15)) # scale and reflection do_plot(ax3, Z, mtransforms.Affine2D().scale(-1, .5)) # everything and a translation do_plot(ax4, Z, mtransforms.Affine2D(). rotate_deg(30).skew_deg(30, 15).scale(-1, .5).translate(.5, -1)) plt.show() |
![]() Python 3.11.2 見直しました。上記のコードでは、下記のエラーが発生します。 Traceback (most recent call last): File "_:\demo_affine_image.py", line 45, in Z = get_image() ^^^^^^^^^^^ File "_:\demo_affine_image.py", line 21, in get_image 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 の改修(先祖帰りバグの改修)を待つしかない。 """ ============================ Affine transform of an image ============================ Prepending an affine transformation (`~.transforms.Affine2D`) to the :ref:`data transform ![]() |
api example code: demo_affine_image.py images-contours-and-fields-affine-image |
|