matplotlib 多个图像共用一个colorbar

网友投稿 272 2022-09-22

matplotlib 多个图像共用一个colorbar

# -*- coding: utf-8 -*-"""Created on Sat Sep 5 18:05:11 2020@author: 15025draw three figures with one common colorbar"""import numpy as npimport matplotlib.pyplot as pltfrom mpl_toolkits.axes_grid1 import ImageGridclass Visualazation: def mainProgram(self): # Set up figure and image grid fig = plt.figure(figsize=(8, 4)) grid = ImageGrid(fig, 111, nrows_ncols=(1,3), axes_pad=0.15, share_all=True, cbar_location="right", cbar_mode="single", cbar_size="7%", cbar_pad=0.15, ) # Add data to image grid for ax in grid: im = ax.imshow(np.random.random((10,10)), vmin=0, vmax=1) # Colorbar ax.cax.colorbar(im) ax.cax.toggle_label(True) plt.show() if __name__ == "__main__": main = Visualazation() main.mainProgram()

结果为:

​​ImageGrid()​​​函数参数说明:​​nrows_ncols=(1,3)​​​表示创建一个​​1​​​行​​3​​​列的画布。​​share_all=True​​​表示所画的图像公用x坐标轴和y坐标轴。​​cbar_locatinotallow="right"​​​表示​​colorbar​​​位于图像的右侧,当然也可以位于上方,下方和左侧。​​cbar_mode="single"​​​表示三个图像公用一个​​colorbar​​​。​​cbar_size="7%"​​​表示​​colorbar​​​的尺寸,默认值为​​5%​​​。​​cbar_pad=0.15​​​表示图像与​​colorbar​​​之间的填充间距,默认值为​​5%​​。可以自行调整以上数值进行尝试。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:小学生躲厕所吃方便面抖音获赞百万,学校42位困难学生获帮扶!
下一篇:python数组中的符号...与:符号的不同之处
相关文章

 发表评论

暂时没有评论,来抢沙发吧~