2017-05-21 44 views
2

我使用的插曲來評估某些條件下,與我創建兩個數組與我的測試條件,例如:「SuperAxis」在matplotlib插曲

A=[ -2, -.1, .1, 2 ] 
B=[ -4, -.2, .2, 4 ] 

然後我評價它在一個循環:

for i,a in enumerate(A): 
    for j,b in enumerate(B): 
     U_E[i][j]=u(t,b,a) 

而完成我繪製它:

f, axarr = plt.subplots(len(A),len(B), sharex=True, sharey='row') 
for i in range(len(A)): 
    for j in range(len(B)): 
     axarr[i, j].plot(t, U_E[i][j]) 

這是不錯的,我用幾乎高興。 :-)它是這樣的:

Matplotlib comparative matrix

但我很願意的AB值添加爲「superaxis」快速查看該BA是每個情節。

喜歡的東西:

Something like this

+0

你忘了告訴我們什麼是 「superaxis」 會。我可以用「superaxis」這個詞註釋一個軸來使它成爲「superaxis」嗎?如果我想要一個「hyperaxis」呢? ;-) – ImportanceOfBeingErnest

+0

我想我已經說清楚了,superaxis是上面整個圖像的兩個正交座標軸,其中'x'座標線將是'B'的內容和'y'座標線將是'A'。 – Lin

+0

@ImportanceOfBeingErnest,我已經添加了一個圖片和我的目標,對於壞的版本抱歉,我對圖像編輯器根本不擅長。 (順便說一句,我不希望「superaxis」數字覆蓋每個矩陣細胞圖像的值)。 – Lin

回答

2

看來你想只標註軸。這可以使用.set_xlabel().set_ylabel()完成。

import matplotlib.pyplot as plt 
import numpy as np 
plt.rcParams["figure.figsize"] = 10,7 

t = np.linspace(0,1) 
u = lambda t, b,a : b*np.exp(-a*t) 

A=[ -2, -.1, .1, 2 ] 
B=[ -4, -.2, .2, 4 ] 

f, axarr = plt.subplots(len(A),len(B), sharex=True, sharey='row') 
plt.subplots_adjust(hspace=0,wspace=0) 
for i in range(len(A)): 
    axarr[i, 0].set_ylabel(A[i], fontsize=20, fontweight="bold") 
    for j in range(len(B)): 
     axarr[i, j].plot(t, u(t,B[j],A[i])) 
     axarr[-1, j].set_xlabel(B[j], fontsize=20,fontweight="bold") 

plt.show() 

enter image description here

3

我建議使用axarr[i,j].text寫的每一個插曲內的A和B參數:

for i in range(len(A)): 
    for j in range(len(B)): 
     axarr[i,j].plot(x, y*j) # just to make my subplots look different 
     axarr[i,j].text(.5,.9,"A="+str(A[j])+";B="+str(B[i]), horizontalalignment='center', transform=axarr[i,j].transAxes) 

plt.subplots_adjust(hspace=0,wspace=0) 
plt.show() 

transform=axarr[i,j].transAxes保證,我們正在採取的座標爲相對於每一個軸:enter image description here

當然,我F你不覺得去耦次要情節是針對你的情況可視化的一個大問題:

for i in range(len(A)): 
for j in range(len(B)): 
    axarr[i,j].plot(x, y*j) 
    axarr[i,j].set_title("A="+str(A[i])+";B="+str(B[j])) 

#plt.subplots_adjust(hspace=0,wspace=0) 
plt.show() 

enter image description here