用颜色条调整子图 [英] adjusting subplot with a colorbar

查看:45
本文介绍了用颜色条调整子图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行了以下可视化.我很茫然地想知道如何根据其他两个子图(它们共享X轴)来调整第三个子图的大小.在

I have made the following visualization. I am at loss to figure out how to adjust the size of the third subplot according to the other two (they are sharing the x-axis). The properties that are given here are not helping much and the examples I found on SO also seem to be addressing cases different from mine. Can anyone please help?

解决方案

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

这篇关于用颜色条调整子图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆