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()
結(jié)果為:

ImageGrid()函數(shù)參數(shù)說明:nrows_ncols=(1,3)表示創(chuàng)建一個1行3列的畫布。share_all=True表示所畫的圖像公用x坐標(biāo)軸和y坐標(biāo)軸。cbar_location="right"表示colorbar位于圖像的右側(cè),當(dāng)然也可以位于上方,下方和左側(cè)。cbar_mode="single"表示三個圖像公用一個colorbar。cbar_size="7%"表示colorbar的尺寸,默認(rèn)值為5%。cbar_pad=0.15表示圖像與colorbar之間的填充間距,默認(rèn)值為5%??梢宰孕姓{(diào)整以上數(shù)值進行嘗試。
到此這篇關(guān)于matplotlib 多個圖像共用一個colorbar的實現(xiàn)示例的文章就介紹到這了,更多相關(guān)matplotlib 共用colorbar內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Django模板之基本的 for 循環(huán) 和 List內(nèi)容的顯示方式
這篇文章主要介紹了Django模板之基本的 for 循環(huán) 和 List內(nèi)容的顯示方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03
YOLOv5中SPP/SPPF結(jié)構(gòu)源碼詳析(內(nèi)含注釋分析)
其實關(guān)于YOLOv5的網(wǎng)絡(luò)結(jié)構(gòu)其實網(wǎng)上相關(guān)的講解已經(jīng)有很多了,但是覺著還是有必要再給大家介紹下,下面這篇文章主要給大家介紹了關(guān)于YOLOv5中SPP/SPPF結(jié)構(gòu)源碼的相關(guān)資料,需要的朋友可以參考下2022-05-05
TensorFlow2.4完成Word2vec詞嵌入訓(xùn)練方法詳解
這篇文章主要為大家介紹了TensorFlow2.4完成Word2vec詞嵌入訓(xùn)練方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-11-11

