我想在图像上绘制多条曲线
使用此代码我相当接近:
G=plt.matplotlib.gridspec.GridSpec(64,1)
fig = plt.figure()
plt.imshow(img.data[:,:],cmap='gray')
plt.axis('off')
plt.axis([0,128,0,64])
for i in arange(64):
fig.add_subplot(G[i,0])
plt.axis('off')
# note that vtc.data.shape = (64, 128*400=51200)
# so every trace for each image pixel is 400 points long
plt.plot(vtc.data[i,:])
plt.axis([0, 51200, 0, 5])
我得到的结果如下所示:
问题是,虽然我似乎能够摆脱水平(x)方向的所有填充,但图像中的填充量不同,垂直方向的堆积图也不同。
我尝试使用
ax = plt.gca()
ax.autoscale_view('tight')
但这也没有减少利润。
如何让 m×n 线图网格与尺寸为 (f m)×(f n) 的放大(因子 f)图像版本精确对齐?
更新和解决方案:@RutgerKassies 的回答效果很好。我使用他的代码实现了它,如下所示:
fig, axs = plt.subplots(1,1,figsize=(8,4))
axs.imshow(img.data[:,:],cmap='gray', interpolation='none')
nplots = 64
fig.canvas.draw()
box = axs._position.bounds
height = box[3] / nplots
for i in arange(nplots):
tmpax = fig.add_axes([box[0], box[1] + i * height, box[2], height])
tmpax.set_axis_off()
# make sure to get image orientation right and
tmpax.plot(vtc.data[nplots-i-1,:],alpha=.3)
tmpax.set_ylim(0,5)
tmpax.set_xlim(0, 51200)