Python:Plots不保存图像中的数据

时间:2014-04-02 20:44:35

标签: python arrays matplotlib cfdata

我正在绘制传感器并将图像保存为png ...文件保存但是它们是空白的,当我运行文件时,只有第一个图表填充了信息。我需要将它们分成自己的数组,而不需要硬编码

import sys
import numpy as np
import matplotlib.pyplot as plt

#file_name = sys.argv[1]

with open('bindata.bin', "rb") as fin:
n_points = int(np.fromfile(fin, dtype=np.float32, count = 1))
n_sensors = int(np.fromfile(fin, dtype=np.float32, count = 1))

print 'Number of measurements per sensor: ', int(n_points)
print 'Number of sensors: ', int(n_sensors)
pressure = n_points * n_sensors
print 'Pressure data: ', pressure

#go back to the beginning of the file
fin.seek(0)

pfluc_dtype = np.dtype([
   ("n_points", np.float32),
   ("n_sensors", np.float32),
   ("velocity1", np.float32),
   ("velocity2", np.float32),
   ("fs_velocity", np.float32),
   ("n_locations", (np.float32, n_sensors)),
   ("cavity_dims", (np.float32,3)),
   ("ref_pressure", np.float32),
   ("pressure", (np.float32, pressure))
   ])
data = np.fromfile(fin, dtype=pfluc_dtype, count =1)

parray = data['pressure'].reshape((n_points,n_sensors))

#print header from list
output = open("header.txt", "wb")
[output.write(x) for x in list(pfluc_dtype.names)]



plt.plot(parray[:524288])
plt.show()
plt.savefig('figure1a.png')
plt.plot(parray[524288:1048576])
plt.show()
plt.savefig('figure2a.png')
plt.plot(parray[1048576:1572864])
plt.show()
plt.savefig('figure3a.png')
plt.plot(parray[1572864:2097152])
plt.show()
plt.savefig('figure4a.png')
plt.plot(parray[2097152:2621440])
plt.show()
plt.savefig('figure5a.png')
plt.plot(parray[2621440:3145728])
plt.show()
plt.savefig('figure6a.png')

1 个答案:

答案 0 :(得分:1)

我打赌问题是plt.show()命令。我认为要使这段代码正常运行,你需要关闭每个数字,然后继续下一个。尝试注释掉所有plt.show()命令。因此,当您运行脚本时,您的图表不会弹出,但我认为它们会正确保存。