2017-05-21 47 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