我正在尝试读取包含线段的 XY 端点和与线段关联的值的文件,然后绘制由给定值着色的线段。我遇到的问题是可能有数十万到数百万个线段,当我尝试读取这些较大的文件时,我遇到了内存错误。有没有更高效的内存方式来做到这一点?
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import matplotlib.cm as cmx
import sys
import csv
if len(sys.argv) > 1:
flofile = sys.argv[1]
else:
flofile = "GU3\GU3.flo"
fig = plt.figure()
ax = fig.add_subplot(111)
jet = cm = plt.get_cmap('jet')
cNorm = colors.Normalize(vmin=0)
scalarMap = cmx.ScalarMappable(norm=cNorm,cmap=jet)
with open(flofile) as FLO:
title = FLO.readline()
limits = [float(tp) for tp in FLO.readline().split()]
FLO.readline()#headers
for line in FLO:
if 'WELLS' in line: break
frac = ([float(tp) for tp in line.split()])
ax.plot([frac[0],frac[2]],[frac[1],frac[3]],color=colorVal)
#ax.plot(*call_list)
scalarMap._A = []
plt.colorbar(scalarMap)
plt.xlim([0,limits[0]])
plt.ylim([0,limits[1]])
plt.show()
此代码适用于小文件。谢谢。