欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

matplotlib 多個圖像共用一個colorbar的實現(xiàn)示例

 更新時間:2020年09月10日 09:58:58   作者:勤奮的小烏賊  
這篇文章主要介紹了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)建一個13列的畫布。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ù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論