Matplotlib:具有3d正交子图和2d图共享轴

时间:2019-05-07 15:16:20

标签: python matplotlib plot mplot3d

我打算在projection="ortho"与2d(轮廓)数据并排的3d对象上绘制与轴对齐的视图,但是我只是想不出如何使垂直轴匹配。

在以下示例中,我希望第二个和第三个子图共享垂直轴: plot produced with the sample code

这是对应的代码:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np

# Make data.
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)

# Plot 3d view
fig = plt.figure(figsize=(16,4))
ax1 = fig.add_subplot(131, projection='3d')
ax1.view_init(40, 60)
surf = ax1.plot_surface(X, Y, Z, cmap=cm.viridis,linewidth=0)

# plot one side
ax2 = fig.add_subplot(132, projection='3d', proj_type = 'ortho')
ax2.view_init(0, 0)
surf = ax2.plot_surface(X, Y, Z, cmap=cm.viridis, linewidth=0)
ax2.set_zlim([-0.2,1])

# plot some 2d information
ax3 = fig.add_subplot(133)
ax3.set_ylim([-0.2,1])

plt.show()

0 个答案:

没有答案