绘图标题与 matplotlib 中的文件名相同
Title of plot same as filename in matplotlib
我想打印绘图的标题,作为绘图的文件名。所以无论它绘制什么文件,它的标题都应该是 'Raman Spectra of filename'。
我正在尝试这种方式,但不起作用
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]))
?
我想打印绘图的标题,作为绘图的文件名。所以无论它绘制什么文件,它的标题都应该是 'Raman Spectra of filename'。 我正在尝试这种方式,但不起作用
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]))
?