一个简单的方法是添加另外两个颜色条,但使它们不可见。
import matplotlib.pyplot as plt
fig, (ax,ax2,ax3) = plt.subplots(3,1, sharex=True)
ax.plot([1,3,5],[1,2,5])
ax2.plot([3,5,9],[4,2,2])
ax3.plot([5,7,12],[1,5,3])
sm = plt.cm.ScalarMappable()
sm.set_array([])
fig.colorbar(sm, ax=ax3)
# add two more colorbars, but make them invisible
fig.colorbar(sm, ax=ax2).ax.set_visible(False)
fig.colorbar(sm, ax=ax).ax.set_visible(False)
plt.subplots_adjust(right=1)
plt.show()