0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

matplotlib 3D グラフ底面に画像の貼り付け

Last updated at Posted at 2021-06-20

maplotlibの3Dグラフの底面に画像を貼り付ける手順メモです。

環境

ubuntu 18.04

install

私の環境のmaplotlibのバージョン(3.4.1)ではmatplotlib._pngというモジュールがインポートできなかったため次のようにして動作するバージョンに変更しました

install
pip3 uninstall matplotlib
pip3 install matplotlib==3.1.0

コード

picture_pathに画像の絶対パスを与えます。

plt_picture.py
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
from matplotlib._png import read_png
from matplotlib.cbook import get_sample_data
from pylab import *

fig = plt.figure()
ax = Axes3D(fig)

picture_path = "/home/hoshina/catkin_ws/src/fast_match/src/search_img3.png"

fn = get_sample_data(picture_path, asfileobj=False)
arr = read_png(fn)

z = 0
X1, Y1 = ogrid[0:arr.shape[0], 0:arr.shape[1]]
ax.plot_surface(X1, Y1, np.atleast_2d(z), rstride=5, cstride=5, facecolors=arr)

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('t')

plt.show()

実行結果

plt_picture.png

参考

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?