我编写了一个脚本来读取数据并将其绘制到图表中。我有三个输入文件
wells.csv:我要创建图表的观察井列表
1201
1202
...
well_summary_table.csv:包含每口井的信息(例如参考高程、水深)
Bore_Name Ref_elev
1201 20
data.csv:包含每个孔的观察数据(例如 pH 值、温度)
RowId Bore_Name 深度 pH
1 1201 2 7
并非 wells.csv 中的所有井都有要绘制的数据
我的脚本如下
well_name_list = []
new_depth_list =[]
pH_list = []
from pylab import *
infile = open("wells.csv",'r')
for line in infile:
line=line.strip('\n')
well=line
if not well in well_name_list:
well_name_list.append(well)
infile.close()
for well in well_name_list:
infile1 = open("well_summary_table.csv",'r')
infile2 = open("data.csv",'r')
for line in infile1:
line = line.rstrip()
if not line.startswith('Bore_Name'):
words = line.split(',')
well_name1 = words[0]
if well_name1 == well:
ref_elev = words[1]
for line in infile2:
if not line.startswith("RowId"):
line = line.strip('\n')
words = line.split(',')
well_name2 = words[1]
if well_name2 == well:
depth = words[2]
new_depth = float(ref_elev) - float(depth)
pH = words[3]
new_depth_list.append(float(new_depth))
pH_list.append(float(pH))
fig.plt.figure(figsize = (2,2.7), facecolor='white')
plt.axis([0,8,0,60])
plt.plot(pH_list, new_depth_list, linestyle='', marker = 'o')
plt.savefig(well+'.png')
new_depth_list = []
pH_list = []
infile1.close()
infile2.close()
它适用于我一半以上的井列表,然后它停止而不给我任何错误消息。我不知道发生了什么事。谁能帮我解决这个问题?对不起,如果这是一个明显的问题。我是新手。
非常感谢,