はじめに
中央の囲まれた部分が動いて見えるオオウチ錯視をmatplotlibで作成して表示する。
コード

解説
モジュールのインポート
データの生成 1

縦方向の模様を作成する。
データの生成 2

横方向の模様を作成する。
図の表示

ax.imshow(im,cmap=”winter”)により、縦方向の模様をベースとして表示する。
中心の円形の図は、patches.Circleの形状に横方向の模様を切り取ることで作成する。
切り取りは、img.set_clip_path(patch)で行うことができ、imgをpatchの形状で切り取って表示することができる。
楕円のオオウチ錯視
切り取る形状はpatchesの種類を変えることで容易にできる。

正方形のオオウチ錯視

参考
オオウチ錯視
錯視

[matplotlib] 42. 画像を任意の形に切り取る
matplotlibのimshowで画像を任意の形状で切り取って表示する方法について解説する。
matplotlib.axes.Axes.set_clip_path — Matplotlib 3.1.0 documentation
コメント