はじめに
背景の遠近感のより生じる錯視であるヘリング錯視をmatplotlibで作成して表示する。
コード

解説
モジュールのインポート
バージョン
任意の傾きの直線を表示
axlineで(x,y)=(0,0)を通る直線を作成する。slopeをiとしてリスト内包表記のfor文により複数個表示する。
垂線の表示
axvline
により、x=0.01と-0.01のところに黒の垂線をひく。
figの保存
bbox_inches=0,pad_inches=0とfig作成時にconstrained_layout=Trueとすることで余白なしの画像データとして保存できる。
参考

ヘリング錯視 - Wikipedia
matplotlib.pyplot.axline — Matplotlib 3.10.0 documentation
matplotlib.pyplot.axvline — Matplotlib 3.10.0 documentation
コメント