【发布时间】:2017-02-21 06:04:06
【问题描述】:
在我的文件系统中,有一些标题和 cmets 以及图形标签。图形标签由@ 开始
如何从日志文件中调用我的标题以及 x 和 y 级别
@提到的?
@ title "RMSD"
@ xaxis label "Time (ns)"
@ yaxis label "RMSD (nm)"
脚本是:
import numpy as np
import matplotlib.pyplot as plt
import csv
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-n","--filename", help="filename on")
args = parser.parse_args()
# example data
filename=(args.filename)
x, y = [],[]
with open(filename) as f:
for line in f:
cols = line.split()
if line.split("#"):
pass
if line.split("@"):
pass
try:
if len(cols) == 2:
x.append(float(cols[0]))
y.append(float(cols[1]))
except ValueError:
pass
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.set_title("Temperature")
ax1.set_xlabel("time in PS")
ax1.set_ylabel("temp in K")
ax1.plot (x,y, c='r', label='the data')
leg = ax1.legend ()
plt.savefig('data.png', dpi=500)
文件格式为:
# This file was created Wed May 25 12:05:43 2016
# Created by:
# :-) GROMACS - gmx rms, VERSION 5.1.2 (-:
#
# Executable: /usr/local/bin/gmx
# Data prefix: /usr/local
# Command line:
# gmx rms -s md_0_1.tpr -f md_0_1_noPBC.xtc -o rmsd.xvg -tu ns
# gmx rms is part of G R O M A C S:
#
# Great Red Oystrich Makes All Chemists Sane
#
@ title "RMSD"
@ xaxis label "Time (ns)"
@ yaxis label "RMSD (nm)"
@TYPE xy
@ subtitle "Backbone after lsq fit to Backbone"
0.0000000 0.0005027
0.0100000 0.0691386
【问题讨论】:
-
您需要在包含标签的日志文件中提供准确行样本。目前,完全不清楚这是带有多个
@标志的单行还是多行。请edit相应的问题。
标签: python-3.x csv matplotlib