【发布时间】:2016-03-08 03:25:00
【问题描述】:
我有变量 x 和 y
def function(a,b):
x = x[(x>a)*(x<b)]
y = y[(y<a)*(y>b)]
# perform some fitting routine using curve_fit on x and y
fig = plt.figure()
ax = fig.add_subplot(111)
phist,xedge,yedge,img = ax.hist2d(x,y,bins=20,norm=LogNorm())
im = ax.imshow(phist,cmap=plt.cm.jet,norm=LogNorm(),aspect='auto')
fig.colorbar(im,ax=ax)
fig.show()
一切正常。但是我有6对不同的输入参数a和b。我想以某种方式使用循环调用function(a,b),并将六个不同的x 和y(对应于6 个输入对)绘制为6 个子图。
像我们一样
ax1 = fig.add_subplot(231) # x vs y for a1,b1
ax2 = fig.add_subplot(232) # x vs y for a2,b2
....
ax6 = fig.add_subplot(236) # x vs y for a6,b6
我想知道如何继续获得最终的子情节!
我知道可以通过指定不同的变量来手动完成,例如x1 和y1 用于第一个输入对a 和b,以此类推其他6 对(x2,y2...,x6,y6)。但这将是一个非常冗长且令人困惑的代码。
【问题讨论】:
标签: python function python-2.7 matplotlib subplot