adjusting subplot with a colorbar

江枫思渺然 提交于 2019-12-02 11:25:41

An easy method would be to add another two colorbars but make them invisible.

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()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!