【发布时间】:2017-11-06 19:56:05
【问题描述】:
使用add_axes 添加残差时,我无法让子图工作。它在没有残差的情况下效果很好,我可以将残差添加到一个图中。这是我正在做的一个例子:
首先,让您了解我正在绘制的内容,(t, y) 是我要绘制的数据,fit 是对数据的拟合,diff 是拟合和数据之间的差异。
t, s, fit = [], [], []
diff = []
for i in range(12):
t.append(x / y[i])
s.append(np.linspace(0, 1, num=100, endpoint=True))
fit.append(UnivariateSpline(t[i], y, er, s=5e20))
diff.append(fit[i](t[i]) - y)
这是这个数字:
fig = plt.figure()
for i in range(12):
plt.subplot(4,3,i+1)
fig.add_axes((0.,0.3,0.7,0.9))
plt.plot(s[i], fit[i](s[i]), 'r-') # this is the fit
plt.errorbar(t[i], y, er, fmt='.k',ms=6) # this is the data
plt.axis([0,1, 190, 360])
fig.add_axes((0.,0.,0.7,0.3))
plot(t[i],diff[i],'or') # this are the residuals
plt.axis([0,1, 190, 360])
如您所见,我生成了 12 个子图,在我添加 fig.add_axes 以将每个子图分隔在 data+fit 和残差之间之前效果很好,但我得到的是一个凌乱的图subplots(图已经缩小看下的subplots):
我想要的是 12 个子图,每个子图如下所示:
【问题讨论】:
标签: python for-loop matplotlib subplot