我想打印绘图的标题,作为它正在绘制的文件名。因此,无论它绘制什么文件,其标题都应为“文件名的拉曼光谱”。 我正在尝试这种方法,但不起作用
def OnPlot(self, event):
cursor= self.conn.execute("SELECT FILE_NAME FROM MOLECULE where MOL_NUMBER==?", (self.plot_list[0],))
files = cursor.fetchall()
#print files[0][0]
tf = open(files[0][0],'r+')
d = tf.readlines()
tf.seek(0)
for line in d:
s=re.search(r'[a-zA-Z]',line)
if s:
tf.write('#'+line)
else:
tf.write(line)
tf.truncate()
tf.close()
plt.plotfile(str(files[0][0]), delimiter=' ',comments = '#', cols=(0, 1),
names=('Raman Shift ($\mathregular{Cm^{-1}}$)', 'Intensity (arb. units)'), )
plt.title('Raman Spectra of "files"')
plt.show()
最佳答案
这个问题有点模糊:)类似于
plt.title('Raman Spectra of {}'.format(files[0][0]))
?
关于python-2.7 - 绘图标题与 matplotlib 中的文件名相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45309481/