在子图之外放置多个颜色条 (matplotlib)
I have a figure with multiple subplot rows that all share an x axis.
Some of the rows require a color bar, but the other rows don't.
If I just use the color bar function, the subplots will be misaligned.
How do I place the color bars outside of the subplots such that all the rows will still be aligned?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我做了一个可能有帮助的函数:
I made a function that may help:
sharex=True
和layout='constrained'
参数(如 @drmuelr 指出的)应该足以解决您的问题。即
fig,axes = plt.subplots(3,1, sharex = True,layout='constrained')
在您的情况下。Matplotlib 现在有关于如何排列颜色条的良好文档: https:// matplotlib.org/stable/users/explain/axes/colorbar_placement.html
The
sharex=True
andlayout='constrained'
argument (as pointed out by @drmuelr) should be sufficient to solve your problem.i.e.
fig, axes = plt.subplots(3,1, sharex = True, layout='constrained')
in your case.Matplotlib by now has good documentation on how to arrange the colorbar here: https://matplotlib.org/stable/users/explain/axes/colorbar_placement.html