0
我试图实现由子图形成的生成图:plt.plot()
和plt.matshow()
,其中两个图具有完全相同的大小。我的意思是一个地块的下边界和第二个地块的下边界位于相同的“高度”。与顶部边界线类似。当前效果显示在下图中。matplotlib中子图的相对大小
我还没有找到任何方式可用的资源,这将有助于我实现这一效果。如果你能帮助我,我将不胜感激。你有
shape=(2500, 2500)
matrix=np.zeros(shape)
print "Start of computing"
for x in range(shape[0]) :
for y in range(shape[1]) :
matrix[x, y]=shapeFuction((x-shape[0]/2)/13.0, (y-shape[1]/2)/13.0, 2.0e-4, 9e-5, 1.0)
print "Start of plotting"
fig=plt.figure()
ax = fig.add_subplot(1,2,2, aspect=1)
ax.matshow(matrix, cmap="autumn") #data[250:501,150:351])
ax.set(adjustable='datalim', aspect=1)
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.xaxis.set_ticks_position('bottom')
ax.set(adjustable='box-forced') #adjustable='datalim'
ax.grid(b=False)
print "Start of plotting part 2"
ax = fig.add_subplot(1,2,1)
phase=(9.0e-5*np.power(np.arange(0, shape[1])-shape[1]/2,3))/7
g=ax.get_ylim()
asp=shape[1]/float(abs(g[0]-g[1]))
ax.plot(phase) #data[250:501,150:351])
ax.set(adjustable='box-forced')#, aspect=1.06/6.0) #adjustable='datalim''box-forced'
ax.set_xlabel("x")
ax.set_ylabel("Phase")
plt.savefig('testData-x3.png')
# plt.show()
第二个选项是我正在寻找的。但是我得到以下错误,我不明白哪个起源。你能看看这个吗? 'UnicodeWarning:统一等于比较未能两个参数为Unicode转换 - 将它们解释为是不平等的 如果方面==“正常”: UnicodeWarning:统一等于比较未能两个参数为Unicode转换 - 将它们解释为是不平等的 ('等于','自动')中的elif方面:' –
好的。我只需要将其转换为Python float。感谢您的有效帮助! –
我编辑了导致警告的那一行,谢谢指出。 – ImportanceOfBeingErnest