0

我正在为传感器绘图并将图像另存为 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')
4

1 回答 1

1

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

于 2014-04-02T20:51:09.607 回答