1 回答
TA贡献1775条经验 获得超8个赞
我做了很多研究,但找不到添加仅包含 3D 图形的图像的方法。所以我使用了subplots,这是一个3D+2D的图,参考官方的。不幸的是,图形的右侧被设置为 3D 图形的中心并且无法移动。这不是您正在寻找的答案,但您可能会发现它很有用。
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()
添加回答
举报