matplotlib 多個圖像共用一個colorbar的實現(xiàn)示例
本文主要介紹了matplotlib 多個圖像共用一個colorbar的實現(xiàn)示例,分享給大家,具體如下:
# -*- coding: utf-8 -*- """ Created on Sat Sep 5 18:05:11 2020 @author: 15025 draw three figures with one common colorbar """ import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import ImageGrid class 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()
函數(shù)參數(shù)說明:nrows_ncols=(1,3)
表示創(chuàng)建一個1
行3
列的畫布。share_all=True
表示所畫的圖像公用x坐標軸和y坐標軸。cbar_location="right"
表示colorbar
位于圖像的右側,當然也可以位于上方,下方和左側。cbar_mode="single"
表示三個圖像公用一個colorbar
。cbar_size="7%"
表示colorbar
的尺寸,默認值為5%
。cbar_pad=0.15
表示圖像與colorbar
之間的填充間距,默認值為5%
??梢宰孕姓{整以上數(shù)值進行嘗試。
到此這篇關于matplotlib 多個圖像共用一個colorbar的實現(xiàn)示例的文章就介紹到這了,更多相關matplotlib 共用colorbar內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Django模板之基本的 for 循環(huán) 和 List內容的顯示方式
這篇文章主要介紹了Django模板之基本的 for 循環(huán) 和 List內容的顯示方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03TensorFlow2.4完成Word2vec詞嵌入訓練方法詳解
這篇文章主要為大家介紹了TensorFlow2.4完成Word2vec詞嵌入訓練方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-11-11