0

I'm plotting for the sensors and saving the images as png... the files save but they're blank and when I run the file, only the first plot is populated with information. and i need to separate these into their own arrays without hardcoding

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')
AmyCS
  • 1
  • possible duplicate of [Matplotlib (pyplot) savefig outputs blank image](http://stackoverflow.com/questions/9012487/matplotlib-pyplot-savefig-outputs-blank-image) – Ffisegydd Apr 02 '14 at 20:57

1 Answers1

1

I bet the problem is the plt.show() command. I think for this code to run properly you would need to close each figure before continuing on to the next one. Try commenting out all plt.show() commands. So your plots wont pop up when you run the script but I think they will save correctly.

bveb333
  • 106
  • 3
  • yeah i had just done that a moment ago, just playing around to see what would happen and it worked. that's so weird – AmyCS Apr 02 '14 at 20:55