はじめに
matplotlibのscatter plotで画像を表示する方法について説明する。画像を表示する関数であるimshowと比較した結果も表示する。
コード&解説
モジュールのインポートなど
バージョン
画像の読み込み
skimageのネコ画像を読み込む。
imshow()で表示
ネコ画像をimshowで表示すると以下のようになる。

散布図で表示する
plt.scatter()の場合はx,yデータが必要なので、画像サイズを利用して、np.arrange()とnp.meshgrid()で作成する。
scatterで画像を表示すると以下のようになる。c=のところでRGBデータを読み込ませることで色を反映させている。imshow()と同様の画像が表示されている。

imshowとscatterを比較
横に並べて表示してもほぼ同じである。

imshowとscatterを比較 拡大して表示
ほぼ同じ位置を拡大して表示すると散布図は点で構成されていることがわかる。

参考
matplotlib.pyplot.scatter — Matplotlib 3.10.0 documentation
コメント