我试图让两个子图的y尺度达到相同的比例,例如。子图1(3d)看起来不小于子图2(2d)。我尝试在行sharey
中添加ax2 = fig.add_subplot(1, 2, 2, )
参数。我认为这与子图1没有填充给定范围有关。
我的工作代码示例是:
from numpy import *
import mpl_toolkits.mplot3d.axes3d as p3
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(10,10), )
ax1 = fig.add_subplot(1, 2, 1, projection="3d", )
u=r_[0:2*pi:300j]
v=r_[0:2*pi:300j]
xi, yi, zi = 11.0, 11.0, 13.0
x=xi*outer(cos(u),sin(v))
y=yi*outer(sin(u),sin(v))
z=zi*outer(ones(size(u)),cos(v))
ax1.plot_surface(x,y,z, color="green", edgecolor="none", alpha=.5 )
ax1.view_init(elev=2., azim=40)
ax2 = fig.add_subplot(1, 2, 2, )
pv = [14.05816239,38.8005282,59.04428205,74.78942393,86.03595384,92.78387179, \
95.03317777,92.78387179,86.03595384,74.78942393,59.04428205,38.8005282, \
14.05816239]
x = linspace(-13, 13, 13)
ax2.barh(x - 1, pv / sum(pv), 2, color="none", edgecolor="grey")
plt.show()
输出如下: