1 回答

TA貢獻(xiàn)1775條經(jīng)驗 獲得超8個贊
我做了很多研究,但找不到添加僅包含 3D 圖形的圖像的方法。所以我使用了subplots,這是一個3D+2D的圖,參考官方的。不幸的是,圖形的右側(cè)被設(shè)置為 3D 圖形的中心并且無法移動。這不是您正在尋找的答案,但您可能會發(fā)現(xiàn)它很有用。
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.patches as patches
import matplotlib.cbook as cbook
fig = plt.figure(figsize=(18,9))
test_img = '/Users/youraccount/Documents/Python/stackoverflow/logo-the-overflow.png'
with cbook.get_sample_data(test_img) as image_file:
image = plt.imread(image_file)
# Make data
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
x = 10 * np.outer(np.cos(u), np.sin(v))
y = 10 * np.outer(np.sin(u), np.sin(v))
z = 10 * np.outer(np.ones(np.size(u)), np.cos(v))
ax = fig.add_subplot(121, projection='3d')
# Plot the surface
ax.plot_surface(x, y, z)
# Placement 0, 0 would be the bottom left, 1, 1 would be the top right.
ax.text2D(1.5, 0.3, "2D Text", transform=ax.transAxes, fontsize=24)
ax = fig.add_subplot(122)
im = ax.imshow(image)
patch = patches.Rectangle(xy=(1.0, -0.5), width=708, height=144, transform=ax.transData)
im.set_clip_path(patch)
ax.axis('off')
plt.show()
添加回答
舉報